Commit 0b743168 authored by Minkush's avatar Minkush

Add scripts in respective directories

parent eb4ef2a6
#!/usr/bin/python
# -*- coding: utf-8 -*-
import datetime
import email
import imaplib
import mailbox
import phonenumbers
import getpass
from phonenumbers import geocoder
from phonenumbers import carrier
from phonenumbers import timezone
def extract_mail_data(email_account, password):
# Connecting to gmail server using IMAP
mail = imaplib.IMAP4_SSL('imap.gmail.com')
mail.login(email_account, password)
mail.list()
mail.select('inbox')
# ALL or UNSEEN mail
(result, data) = mail.uid('search', None, 'ALL')
data_length = len(data[0].split())
# Fetching emails, sender, receiver, message, date-time
for email_sequence in range(data_length):
latest_email_uid = data[0].split()[email_sequence]
(result, email_data) = mail.uid('fetch', latest_email_uid,
'(RFC822)')
raw_email = email_data[0][1]
raw_email_string = raw_email.decode('utf-8')
email_message = email.message_from_string(raw_email_string)
# Header Details
date_tuple = email.utils.parsedate_tz(email_message['Date'])
if date_tuple:
local_date = \
datetime.datetime.fromtimestamp(email.utils.mktime_tz(date_tuple))
local_message_date = '%s' \
% str(local_date.strftime('%a, %d %b %Y %H:%M:%S'))
email_sender = email.header.decode_header(email_message['From'])
email_receiver = email.header.decode_header(email_message['To'])
email_sub = email.header.decode_header(email_message['Subject'])
email_from = str(email.header.make_header(email_sender))
email_to = str(email.header.make_header(email_receiver))
subject = str(email.header.make_header(email_sub))
# Body details
for part in email_message.walk():
if part.get_content_type() == 'text/plain':
body = part.get_payload(decode=True)
file_name = 'email_' + str(email_sequence) + '.txt'
output_file = open(file_name, 'w')
text = body.decode('utf-8')
# Searching for phone numbers from email's body
for match in phonenumbers.PhoneNumberMatcher(text,
None):
sender = 'From: %s' % email_from
print(sender)
output_file.write(str(sender) + '\n')
# Converting phone numbers to International format
phone_no = phonenumbers.format_number(match.number,
phonenumbers.PhoneNumberFormat.E164)
print(phone_no)
output_file.write(phone_no + '\n')
# Location of phone numbers
ph_location = \
geocoder.description_for_number(match.number,
'en')
print(ph_location)
output_file.write(ph_location + '\n')
# Carrier's name of the number
ph_carrier = carrier.name_for_number(match.number,
'en')
print(ph_carrier)
output_file.write(ph_carrier + '\n')
# Timezone for phone numbers
ph_timezone = \
timezone.time_zones_for_number(match.number)
print(ph_timezone)
output_file.write(str(ph_timezone) + '\n' + '\n')
print('\n')
output_file.close()
else:
print('Not found')
# Stand-alone script condition
if __name__ == '__main__':
user_email = input('Enter your email: ')
password = getpass.getpass()
extract_mail_data(user_email, password)
#!/usr/bin/python
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
# Extract the Firefox driver and place in the same folder as this file.
browser = webdriver.Firefox()
# Github new account registration website's URL
browser.get('https://github.com/join')
# In GUI, the email, name would already be stored from sign-up module
# Then, user only needs to enter username and password
def github_account(username, email, password):
user_name = browser.find_element_by_id('user_login')
user_name.send_keys(username)
user_email = browser.find_element_by_id('user_email')
user_email.send_keys(email)
user_password = browser.find_element_by_id('user_password')
user_password.send_keys(password)
submit = browser.find_element_by_id('signup_button')
submit.click()
browser.quit()
if __name__ == '__main__':
username = input('Enter username: ')
email = input('Enter email: ')
password = input('Enter password: ')
github_account(username, email, password)
print ('Congrats! Your new Github account has been created.')
print ('Check your mail to verify it.')
import pytest
import string
import random
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from github_register import *
class TestRegisteration:
def test_github_account(self):
random_id = ''.join([random.choice(string.ascii_letters
+ string.digits) for n in range(8, 18)])
random_string = random_id
user_email = random_string + "@xyz.com"
username = random_string
github_account(username, user_email, "testpassword1234")
WebDriverWait(browser, 10)
text="You’ve taken your first step into a larger world, @" + username + "."
assert browser.find_element_by_class_name("lead").text == text
\ No newline at end of file
......@@ -102,7 +102,7 @@ def list_channel():
while 1:
connection_str = ":%s MODE %s :+i" %(irc_nick, irc_nick)
connection_str = ":%s MODE %s :+Ri" %(irc_nick, irc_nick)
data = s.recv(1024).decode('UTF-8', errors="ignore")
......@@ -141,7 +141,7 @@ def join_channel(channel):
s.send(bytes('JOIN %s\r\n' %(channel), 'UTF-8'))
while 1:
while 1:
data = s.recv(1024).decode('UTF-8', errors="ignore")
readbuffer = readbuffer + data
......
#!/usr/bin/python
# -*- coding: utf-8 -*-
import sys
import socket
import string
import time
import getpass
def socket_conn():
global s, HOST, PORT
HOST = 'irc.freenode.net'
PORT = 6667
s = socket.socket()
s.connect((HOST, PORT))
def server_conn(REALNAME, NICK):
IDENT = irc_nick
s.send(bytes('NICK %s\r\n' % NICK, 'UTF-8'))
s.send(bytes('USER %s %s bla :%s\r\n' % (IDENT, HOST, REALNAME),
'UTF-8'))
def nick_register(
NICK,
mail,
password,
):
# Invalid nickname error
error1 = False
# Invalid email error
error2 = False
global irc_nick, email
server_conn(user_name, NICK)
s.send(str.encode('PRIVMSG NickServ :REGISTER %s %s\r\n'
% (password, mail)))
while 1:
data = s.recv(1024).decode('UTF-8', errors="ignore")
print(data)
if "already registered" in data:
error1 = True
break
elif "not a valid email address" in data:
error2 = True
break
elif "activation instructions" in data:
break
s.close()
if error1 == True:
print("\nThe IRC nickname you have entered is already registered.\n")
irc_nick = input("Enter another IRC nickname: \n")
socket_conn()
nick_register(irc_nick, email, password)
elif error2 == True:
print("\nThe email you have entered is not a valid.\n")
email = input("Enter another email address: \n")
socket_conn()
nick_register(irc_nick, email, password)
print("\nYour nickname has been successfully registered\
on the server. Check your email for further instructions!\n\n")
# Waiting server for 5s for user.
time.sleep(5)
def list_channel():
socket_conn()
server_conn(user_name,irc_nick)
s.send(bytes('PRIVMSG alis :LIST #debian* -min 30\r\n', 'UTF-8'))
global bufferdata
bufferdata = ""
while 1:
connection_str = ":%s MODE %s :+Ri" %(irc_nick, irc_nick)
data = s.recv(1024).decode('UTF-8', errors="ignore")
bufferdata = bufferdata + '%s\n' %(data)
if "End of output" in data:
break
s.close()
# Not display data before channels list
if connection_str in bufferdata:
l = bufferdata.index(connection_str)
print(bufferdata[l+27:])
def join_channel(channel):
readbuffer = ''
socket_conn()
server_conn(user_name,irc_nick)
time.sleep(10)
# Verifying nickname on the server.
s.send(bytes('PRIVMSG NickServ :IDENTIFY %s\r\n' %(password), 'UTF-8'))
# Waiting for server to respond.
time.sleep(10)
# Joining channel
s.send(bytes('JOIN %s\r\n' %(channel), 'UTF-8'))
while 1:
data = s.recv(1024).decode('UTF-8', errors="ignore")
readbuffer = readbuffer + data
temp = str.split(readbuffer, '\n')
readbuffer = temp.pop()
for line in temp:
line = str.rstrip(line)
line = str.split(line)
# ping pong protocol
if line[0] == 'PING':
s.send(bytes('PONG %s\r\n' % line[1], 'UTF-8'))
print(data)
if __name__ == '__main__':
socket_conn()
print('This Program will automate IRC Nickname Registration,\
Displaying List of Channels and Joining them.\n')
user_name = input('Enter your name: ')
irc_nick = input('Enter the IRC nickname you want to register: ')
email = input('Enter your email: ')
password = getpass.getpass('Enter password for your nickname: ')
socket_conn()
nick_register(irc_nick, email, password)
display_channels = input("Do you want to display the list of available 'debian' channels? (Y/N) ").upper()
if display_channels == "Y":
list_channel()
irc_channel = input("Enter the channel you want to join: ")
join_channel(irc_channel)
else:
irc_channel = input("Enter the channel you want to join: ")
join_channel(irc_channel)
#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
# Submitting user email on the website
def subscribe_mailing_list(list_name, email):
# A session object has all methods of requests API
client = requests.Session()
url = 'https://lists.debian.org/cgi-bin/subscribe.pl'
client.get(url)
login_data = {'user_email': email, 'list': list_name,
'action': 'Subscribe'}
client.post(url, data=login_data, stream=True)
# Confirming subscription by replying to the mail
def reply_by_mail(reply_code):
reply_subject = 'CONFIRM ' + reply_code # Final Subject of reply mail
sender = 'gsocdebian@gmail.com' # Sender's email address (don't change)
receiver = list_name + '-request@lists.debian.org'
msg = MIMEMultipart()
msg['From'] = sender
msg['To'] = receiver
msg['Subject'] = reply_subject
body = 'Subscribe'
msg.attach(MIMEText(body, 'plain'))
# Connects to server using port 587
server = smtplib.SMTP('smtp.gmail.com', 587)
server.starttls()
# " " contains sender's password (don't change)
server.login(sender, 'testuser')
text = msg.as_string()
server.sendmail(sender, receiver, text)
server.quit()
# For stand-alone script
if __name__ == '__main__':
print('This is a program to automate the process of subscription to the'
, 'mailing list.\n')
# Listing all mailing lists options
print('''Mailing lists: debian-outreach
\t\t debian-news
\t\t''',
'''debian-announce
\t\t debconf-announce
\t\t debian-devel-announce''',
'''
\t\t debian-events-apac
\t\t debian-events-eu
\t\t''',
'''debian-events-na
\t\t debian-events-ha
\t\t debian-dug-in
''')
list_name = input('Enter the list which you want to subscribe: ')
email = input('Enter you email: ') # User's email
subscribe_mailing_list(list_name, email)
print('\nCheck your email for further instructions!')
reply_code = input('\nEnter the code of the subject you recieved\
in your email: ')
reply_by_mail(reply_code)
print('\nCongrats, you are successfully subscribed to % s mailing list!' \
% list_name)
k = input('\nPress any key to exit')
#!/usr/bin/python
# -*- coding: utf-8 -*-
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
# Extract the Firefox driver and place in the same folder as this file.
browser = webdriver.Firefox()
# Salsa new account registration website's URL
browser.get('https://signup.salsa.debian.org/register/guest/')
# In GUI, the email, name would already be stored from sign-up module
# Then, user only needs to enter username and password
def create_salsa_account(user_name, full_name, user_email, user_password):
username = browser.find_element_by_id('username_prefix')
username.send_keys(user_name)
name = browser.find_element_by_id('name')
name.send_keys(full_name)
email = browser.find_element_by_id('email')
email.send_keys(user_email)
pwd = browser.find_element_by_id('password')
pwd.send_keys(user_password)
cpwd = browser.find_element_by_id('confirm')
cpwd.send_keys(user_password)
submit = \
browser.find_element_by_xpath('//input[@value = "Register account"]')
submit.click()
browser.quit()
if __name__ == '__main__':
user_name = input('Enter username: ')
full_name = input('Enter Name: ')
user_email = input('Enter email: ')
user_password = input('Enter password: ')
create_salsa_account(user_name, full_name, user_email, user_password)
print('Congrats! Your new Salsa account has been created.')
print('Check your mail for further instructions')
import pytest
import string
import random
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.keys import Keys
from salsa_account import *
class TestRegisteration:
def test_create_salsa_account(self):
random_id = ''.join([random.choice(string.ascii_letters
+ string.digits) for n in range(8, 18)])
random_string = random_id
user_email = random_string + "@sdf.com"
username = random_id
create_salsa_account(username, "FullName", user_email,"testpassword")
WebDriverWait(browser, 10)
text = "Your requested user account "+username+"-guest was successfully created."
assert browser.find_element_by_tag_name("p").text == text
#!/usr/bin/python
# -*- coding: utf-8 -*-
import os, os.path
import psutil
# Ending Thunderbird process
PROCNAME = 'thunderbird'
for proc in psutil.process_iter():
if proc.name() == PROCNAME:
proc.kill()
# Editing Thunderbird's config
def edit_config(username):
name_of_file = 'user.js'
# new Preferences
toFile = \
'''user_pref("mail.attach_vcard", true);
user_pref("mail.biff.play_sound", false);
user_pref("mail.biff.show_alert", false);
user_pref("mail.collect_email_address_outgoing", true);
user_pref("mail.default_html_action", 0);
user_pref("mail.html_compose", false);
user_pref("mailnews.reply_header_type", 2);
user_pref("mailnews.reply_on_top", 1);
user_pref("mailnews.reply_with_extra_lines", 1);'''
# finding path
file_path = []
for r, d, f in os.walk("/home/%s/.thunderbird/" % username):
for files in f:
if files == "prefs.js":
path = os.path.join(r, files)
file_path.append(path)
# Editing the path
if response == "Y":
for i in range(len(file_path)):
save_path = file_path[i][0:-9]
completeName = os.path.join(save_path, name_of_file)
file1 = open(completeName, 'w')
file1.write(toFile)
file1.close()
elif response == "N":
profile = input("Enter the name of the\
profile which you want to edit: ")
for i in range(len(file_path)):
if profile in file_path[i]:
save_path = file_path[i][0:-9]
completeName = os.path.join(save_path, name_of_file)
file1 = open(completeName, 'w')
file1.write(toFile)
file1.close()
else:
print("Profile not found")
break
else:
print("Wrong Response")
if __name__ == '__main__':
print('Program to close Thunderbird application\
and edit its configuration settings\n')
username = input("Enter your PC's user name: ")
response = input("Do you want to edit configuration for all\
your profiles (y/n) ").upper()
edit_config(username)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment