def login(self): bot = self.bot bot.get( 'https://twitter.com/') # Get the content of https://twitter.com/ time.sleep(self.generate_random() ) # This line of code WHEREVER wait for n [5-8] seconds. try: email = bot.find_element_by_class_name( "email-input") # Get the email input field. password = bot.find_element_by_name( 'session[password]') # Get the password input field. email.clear() # clear the email input field password.clear() # clear the password input field email.send_keys(self.username) # confirm password.send_keys(self.password) password.send_keys(Keys.RETURN) # send the inputs entered time.sleep(self.generate_random()) auth_flag = None try: auth_flag = bot.find_element_by_css_selector( "h1.Icon.Icon--bird.bird-topbar-etched" ) # auth_flag = get the bird icon on top of the page if the authentication is Okay except Exception as ex: write_log(ex) usage.print_usage(1) if (auth_flag != None): # if the user is authorized follower_elem = bot.find_element_by_css_selector( 'li.ProfileCardStats-stat:nth-child(3) > a:nth-child(1) > span:nth-child(2)' ) self.followers = follower_elem.get_attribute( 'data-count') # get the followers count return True except Exception as ex: write_log(ex) usage.print_usage(2)
def process(args): if len(args) < 2: usage.print_usage() return cmd_name = args[1] if not (cmd_name in handlers.keys()): logging.critical("Bad command given!") return else: handlers[cmd_name](args[2:len(args)])
def build_Edo(): email_password = getpass.getpass('Insert password for ' +email_email +':') # password input via getpass edoBot = TwitterBot(email_email,email_password,0,0,keywords,0) #create the bot network_status = check_connection() if (not network_status): usage.print_usage(6) # if the network connection isn't active authenticated = edoBot.login() # login if(authenticated): if(check_user.check_if_user_exists(edoBot.username,edoBot.password)): print('Welcome back, ' + edoBot.username + ' !') else: print('Logged in as '+edoBot.username+' !') return edoBot
def build_Edo(): email_password = getpass.getpass("Insert password for " + email_email + ":") # password input via getpass edoBot = TwitterBot(email_email, email_password, 0, 0, keywords, 0) # create the bot network_status = check_connection() if not network_status: usage.print_usage(6) # if the network connection isn't active authenticated = edoBot.login() # login if authenticated: if check_user.check_if_user_exists(edoBot.username, edoBot.password): print("Welcome back, " + edoBot.username + " !") else: print("Logged in as " + edoBot.username + " !") return edoBot
def check_if_user_exists(username,password): if(db_is_new): usage.print_usage(5) else: conn = sqlite3.connect(db_filename) cursor = conn.cursor() p = hashlib.sha256(password.encode('utf-8')).hexdigest() cursor.execute("SELECT * FROM users WHERE username = ? and password= ?", (username,p)) data=cursor.fetchone() if (data==None): cred = (username,p) create_user(conn,cred,username) return False else: return True
def check_stat(username, password): timestamps = [] # contains all the timestamps saved in the records likes = [] # contains all the likes saved in the records retweets = [] # contains all the retweets saved in the records followers = [] # contains all the followers saved in the records d_likes = {} # dictionary with as keys = days & values = likes d_retweets = {} # dictionary with as keys = days & values = retweets d_followers = {} # dictionary with as keys = days & values = followers if (db_is_new): usage.print_usage(5) else: cursor = conn.cursor() # check if that user is in the database cursor.execute( "SELECT * FROM users WHERE username = ? and password = ?", (username, password)) data = cursor.fetchone() if (data == None): print("There aren't data for this username.") sys.exit() # if that user exists cursor.execute("SELECT * FROM analytics WHERE username = ?", (username, )) data = cursor.fetchall() if (data != None): if (len(data) != 0): for record in data: timestamps += [record[1]] # save the timestamp likes += [int(record[2])] # save the likes count retweets += [int(record[3])] # save the retweets count followers += [int(record[4])] # save the followers count # In this for loop all the arrays here declared become dictionary in this way: # All the likes, followers and retweets counts are aggregate per day. # Remember timestamps[:-16] means yyyy-mm-dd for i in range(len(timestamps)): if (not (timestamps[i][:-16] in d_likes)): for j in range(len(timestamps)): if timestamps[i][:-16] == timestamps[j][:-16]: if timestamps[i][:-16] in d_likes: d_likes[timestamps[i][:-16]] += likes[j] else: d_likes[timestamps[i][:-16]] = likes[j] if timestamps[i][:-16] in d_retweets: d_retweets[timestamps[i] [:-16]] += retweets[j] else: d_retweets[timestamps[i] [:-16]] = retweets[j] if timestamps[i][:-16] in d_followers: d_followers[timestamps[i] [:-16]] -= d_followers[ timestamps[i][:-16]] d_followers[timestamps[i] [:-16]] = followers[j] else: d_followers[timestamps[i] [:-16]] = followers[j] # adjust plot settings plt.subplots_adjust(bottom=0.2) plt.xticks(rotation=70) ax = plt.gca() ax.xaxis_date() date = list(d_likes.keys()) likes_vector = [d_likes[i] for i in date] retweets_vector = [d_retweets[i] for i in date] followers_vector = [d_followers[i] for i in date] plt.plot(date, likes_vector, '-r', marker='o', label='likes') plt.plot(date, retweets_vector, '-g', marker='o', label='retweets') plt.plot(date, followers_vector, '-b', marker='o', label='followers') # if first > last element so the legend is shown on the right. Otherwise It's shown on the left if (d_likes[list(d_likes.keys())[0]] > d_likes[list( d_likes.keys())[len(d_likes) - 1]]): plt.legend(loc='upper right') else: plt.legend(loc='upper left') # Print the results print('Total likes: ' + str(sum(likes))) print('Total retweets: ' + str(sum(retweets))) # add the number label in all points for var_date, var_likes in zip(date, likes_vector): plt.text(var_date, var_likes, str(var_likes)) for var_date, var_retweets in zip(date, retweets_vector): plt.text(var_date, var_retweets, str(var_retweets)) for var_date, var_followers in zip(date, followers_vector): plt.text(var_date, var_followers, str(var_followers)) plt.title('Statistics for ' + username) plt.subplots_adjust(left=None, bottom=0.13, right=0.98, top=0.94, wspace=None, hspace=None) plt.show() else: print("There aren't data for this username.") conn.close()
This file is under MIT License. """ # all libraries required import os import sys import usage import sqlite3 try: import matplotlib.pyplot as plt plt.figure(num='twitterBot stats') except Exception as ex: usage.print_usage(4) db_filename = 'database.db' db_is_new = not os.path.exists(db_filename) conn = sqlite3.connect(db_filename) # check the statistics for a user def check_stat(username, password): timestamps = [] # contains all the timestamps saved in the records likes = [] # contains all the likes saved in the records retweets = [] # contains all the retweets saved in the records followers = [] # contains all the followers saved in the records d_likes = {} # dictionary with as keys = days & values = likes d_retweets = {} # dictionary with as keys = days & values = retweets
def add_stat(username, timestamp, likes, retweets, followers): if db_is_new: usage.print_usage(5) else: data = (username, timestamp, likes, retweets, followers) create_stat(conn, data)
#Function that prints dinamically def print_wait_links(): for i in range(5): print('Collecting links' + '.' * i, end='\r') time.sleep(1) print('') ################# IMPORT (OR DOWNLOAD) EXTERNAL LIBRARIES ############## try: from selenium import webdriver from selenium.webdriver.common.keys import Keys except Exception as ex: write_log(ex) usage.print_usage(3) ################# READ INPUT FROM CLI ################ intro(website, version) try: options, remainder = getopt.getopt( sys.argv[1:], 'u:k:smihf:', ['username', 'keywords', 'stat', 'mine', 'info', 'help', 'follow' ]) # all the options allowed for opt, arg in options: if opt in ('-u', '--username'): email_email = arg elif opt in ('-k', '--keywords'): try: keywords_flag = True keywords = arg.split(
#----------------------------------------------- import time import getopt import getpass import random import datetime import check_user import add_result import analyze_stat import sys,usage try: from selenium import webdriver from selenium.webdriver.common.keys import Keys except Exception as ex: usage.print_usage(3) # all the libraries It needs try: options,remainder =getopt.getopt(sys.argv[1:], 'u:h:sm',['username','hashtags','stat','mine']) # all the options allowed for opt, arg in options: if opt in ('-u','--username'): email_email = arg elif opt in ('-h','--hashtags'): try: hashtag_flag = True hashtags = arg.split(',') # if more than one hashtag has been entered, split them and put into hashtags except Exception as ex: usage.print_usage(0) elif opt in ('-s','--stat'): stat_flag = True
def cli_parser(): target = '' cli = { 'nocache': '', \ 'oldconfig': True, \ # typically kernel sources are found here 'kerneldir': '/usr/src/linux', \ 'arch': utils.misc.identify_arch()} verbose = { 'std': '', \ 'set': False, \ 'logfile': '/var/log/kigen.log'} master_conf = {} kernel_conf = {} modules_conf = {} initramfs_conf = {} version_conf = {} url_conf = {} # copy command line arguments cliopts = sys.argv # parse /etc/kigen/master.conf master_conf = etcparser.etc_parser_master() # if not enough parameters exit with usage if len(sys.argv) < 2: usage.print_usage() sys.exit(2) # set default kernel sources if 'kernel-sources' in master_conf: # if set grab value from config file cli['kerneldir'] = master_conf['kernel-sources'] # else: exit if not 'tool' in cliopts and not 't' in cliopts: # don't check for kernel version if we use 'kigen tool' cli['KV'], cli['KNAME'] = utils.misc.get_kernel_version(cli['kerneldir']) # exit if kernel dir doesn't exist if not os.path.isdir(cli['kerneldir']): print(stdout.red('error') + ': ' + cli['kerneldir'] + ' does not exist.') sys.exit(2) # exit if kernel version is not found if cli['KV'] is 'none': print(stdout.red('error') + ': ' + cli['kerneldir']+'/Makefile not found') sys.exit(2) # prevent multiple targets from running if ('k' in cliopts and 'i' in cliopts) or \ ('initramfs' in cliopts and 'kernel' in cliopts) or \ ('k' in cliopts and 'initramfs' in cliopts) or \ ('i' in cliopts and 'kernel' in cliopts) or \ ('t' in cliopts and 'kernel' in cliopts) or \ ('t' in cliopts and 'initramfs' in cliopts) or \ ('tool' in cliopts and 'kernel' in cliopts) or \ ('tool' in cliopts and 'initramfs' in cliopts) or \ ('tool' in cliopts and 'i' in cliopts) or \ ('tool' in cliopts and 'k' in cliopts) or \ ('t' in cliopts and 'i' in cliopts) or \ ('t' in cliopts and 'k' in cliopts): print(stdout.red('error') + ': kigen cannot run multiple targets at once.') sys.exit(2) # === parsing for the kernel target === if 'kernel' in sys.argv or 'k' in sys.argv: # we found the kernel target # parse accordingly if 'kernel' in sys.argv: target = 'kernel' cliopts.remove('kernel') if 'k' in sys.argv: target = 'k' cliopts.remove('k') # parse kernel_conf = etcparser.etc_parser_kernel() try: # parse command line opts, args = getopt(cliopts[1:], "dhn", [ \ "help", \ "version", \ "credits", \ "conf=", \ "dotconfig=", \ "bbconf=", \ "rename=", \ "initramfs=", \ "mrproper", \ "clean", \ "silentoldconfig", \ "defconfig", \ "localmodconfig", \ "localyesconfig", \ "menuconfig", \ "allyesconfig", \ "nomodules", \ "nomodinstall", \ "fakeroot=", \ "allnoconfig", \ "nooldconfig", \ "oldconfig", \ "logfile=", \ "noboot", \ "nosaveconfig", \ "hostbin", \ "fixdotconfig=", \ "module-rebuild", \ "debug"]) except GetoptError as err: print(str(err)) # "option -a not recognized" usage.print_usage() sys.exit(2) # this has to be taken care before quiet is initialized # hence the extra loop, catch --logfile before all cli['logfile'] = '/var/log/kigen.log' if master_conf['logfile'] != '': cli['logfile'] = master_conf['logfile'] for o, a in opts: if o in ("--logfile"): cli['logfile'] = a # default cli['dotconfig'] = master_conf['kernel-sources']+'/.config' if kernel_conf['dotconfig'] != '': cli['dotconfig'] = kernel_conf['dotconfig'] # FIXME # # HACK only use default if we use kigen k if not 'tool' in cliopts and not 't' in cliopts: cli['rename'] = '/boot/kernel-kigen-'+cli['arch']+'-'+cli['KV'] else: cli['rename'] = '' if kernel_conf['rename'] != '': cli['rename'] = kernel_conf['rename'] cli['initramfs'] = '' cli['info'] = False cli['mrproper'] = False if kernel_conf['mrproper'] == 'True': cli['mrproper'] = True cli['localmodconfig'] = False if kernel_conf['localmodconfig'] == 'True': cli['localmodconfig'] = True cli['localyesconfig'] = False if kernel_conf['localyesconfig'] == 'True': cli['localyesconfig'] = True cli['silentoldconfig'] = False if kernel_conf['silentoldconfig'] == 'True': cli['silentoldconfig'] = True cli['defconfig'] = False if kernel_conf['defconfig'] == 'True': cli['defconfig'] = True cli['menuconfig'] = False if kernel_conf['menuconfig'] == 'True': cli['menuconfig'] = True cli['clean'] = False if kernel_conf['clean'] == 'True': cli['clean'] = True cli['allyesconfig'] = False cli['allnoconfig'] = False cli['oldconfig'] = False if kernel_conf['nooldconfig'] == 'False': cli['oldconfig'] = True cli['nomodinstall'] = False if kernel_conf['nomodinstall'] == 'True': cli['nomodinstall'] = True cli['nomodules'] = False if kernel_conf['nomodules'] == 'True': cli['nomodules'] = True # No module support implies not installing modules cli['nomodinstall'] = True cli['fakeroot'] = '/' if kernel_conf['fakeroot'] != '': cli['fakeroot'] = kernel_conf['fakeroot'] cli['nocache'] = False cli['noboot'] = False if kernel_conf['noboot'] == 'True': cli['noboot'] = True # quiet = '2>&1 | tee -a ' + logfile # verbose # quiet = '>>' + logfile + ' 2>&1' # quiet + logfile verbose['std'] = '>>' + cli['logfile'] + ' 2>&1' verbose['set'] = False if master_conf['debug'] == 'True': verbose['set'] = True verbose['std'] = '2>&1 | tee -a ' + cli['logfile'] + ' ; test ${PIPESTATUS[0]} -eq 0' verbose['logfile'] = cli['logfile'] cli['color'] = True cli['nosaveconfig'] = False if kernel_conf['nosaveconfig'] == 'True': cli['nosaveconfig'] = True cli['fixdotconfig'] = '' if kernel_conf['fixdotconfig'] != '': cli['fixdotconfig'] = kernel_conf['fixdotconfig'] cli['module-rebuild'] = False if kernel_conf['module-rebuild'] == 'True': cli['module-rebuild'] = True # target options for o, a in opts: if o in ("-h", "--help"): usage.print_usage_kernel(cli, master_conf, kernel_conf) sys.exit(0) elif o in ("--credits"): usage.print_credits() sys.exit(0) elif o in ("--version"): usage.print_version() sys.exit(0) # have to declare logfile here too elif o in ("--logfile="): cli['logfile'] = a verbose['logfile'] = cli['logfile'] elif o in ("-d", "--debug"): # quiet = '>>' + logfile + ' 2>&1' # logfile # quiet = '2>&1 | tee -a ' + logfile # verbose verbose['std'] = '2>&1 | tee -a ' + cli['logfile'] + ' ; test ${PIPESTATUS[0]} -eq 0' verbose['set'] = True verbose['logfile'] = cli['logfile'] elif o in ("-k", "--dotconfig"): cli['dotconfig'] = a cli['oldconfig'] = True # make sure .config is ok elif o in ("--rename"): cli['rename'] = a elif o in ("--initramfs"): cli['initramfs'] = a elif o in ("--mrproper"): cli['mrproper'] = True elif o in ("--localmodconfig"): cli['localmodconfig'] = True elif o in ("--localyesconfig"): cli['localyesconfig'] = True elif o in ("--silentoldconfig"): cli['silentoldconfig'] = True elif o in ("--defconfig"): cli['defconfig'] = True elif o in ("--menuconfig"): cli['menuconfig'] = True elif o in ("--nooldconfig"): cli['oldconfig'] = False elif o in ("--oldconfig"): cli['oldconfig'] = True elif o in ("--nomodinstall"): cli['nomodinstall'] = True elif o in ("--nomodules"): cli['nomodules'] = True elif o in ("--fakeroot"): # if os.path.isdir(a): cli['fakeroot'] = a # else: # print "%s is not a directory" % a # sys.exit(2) elif o in ("--noboot"): cli['noboot'] = True elif o in ("--nosaveconfig"): cli['nosaveconfig'] = True elif o in ("--clean"): cli['clean'] = True elif o in ("--fixdotconfig"): cli['fixdotconfig'] = a # elif o in ("--getdotconfig"): # cli['getdotconfig'] = a elif o in ("--module-rebuild"): cli['module-rebuild'] = True else: assert False, "uncaught option" # === parsing for the initramfs target === elif 'initramfs' in sys.argv or 'i' in sys.argv: # we found the initramfs target # parse accordingly if 'initramfs' in sys.argv: target = 'initramfs' cliopts.remove('initramfs') if 'i' in sys.argv: target = 'i' cliopts.remove('i') # parse /etc/kigen/initramfs/modules.conf and # /etc/kigen/initramfs/initramfs.conf initramfs_conf, modules_conf, version_conf, url_conf = etcparser.etc_parser_initramfs() try: # parse command line opts, args = getopt(cliopts[1:], "hdn", [ \ "dotconfig=", \ "mrproper", \ "menuconfig", \ "allyesconfig", \ "nooldconfig", \ "defconfig", \ "oldconfig", \ "bin-luks", \ "host-luks", \ "source-luks", \ "source-lvm2", \ "bin-lvm2", \ "host-lvm2", \ "bin-dmraid", \ "host-dmraid", \ "source-dmraid",\ "iscsi", \ "logfile=", \ "bin-evms", \ "host-evms", \ "mdadm", \ "splash=", \ "sres=", \ "sinitrd=", \ "firmware=", \ "bin-disklabel",\ "host-disklabel",\ "source-disklabel",\ "unionfs-fuse", \ "aufs", \ "bin-dropbear", \ "host-dropbear",\ "source-dropbear",\ "linuxrc=", \ "nocache", \ "nomodules", \ "noboot", \ "selinux", \ "help", \ "version", \ "credits", \ "nosaveconfig", \ "hostbin", \ "bin-glibc", \ "host-glibc", \ "libncurses", \ "bin-libncurses",\ "host-libncurses",\ "bin-zlib", \ "host-zlib", \ "rename=", \ "plugin=", \ "rootpasswd=", \ "hostsshkeys", \ "ssh-pubkeys", \ "ssh-pubkeys-file", \ "keymaps=", \ "source-ttyecho",\ "bin-strace", \ "host-strace", \ "source-strace",\ "bin-screen", \ "host-screen", \ "source-screen",\ "debugflag", \ "bin-all", \ "host-all", \ "source-all", \ "bin-busybox", \ "host-busybox", \ "dynlibs", \ "debug"]) except GetoptError as err: print(str(err)) # "option -a not recognized" usage.print_usage() sys.exit(2) # this has to be taken care before quiet is initialized # hence the extra loop, catch --logfile before all cli['logfile'] = '/var/log/kigen.log' if master_conf['logfile'] != '': cli['logfile'] = master_conf['logfile'] for o, a in opts: if o in ("--logfile"): cli['logfile'] = a cli['oldconfig'] = False # too much verbose if initramfs_conf['oldconfig'] == 'True': cli['oldconfig'] = True # default cli['dotconfig'] = '' if initramfs_conf['dotconfig'] != '': cli['dotconfig'] = initramfs_conf['dotconfig'] cli['oldconfig'] = True # make sure .config is ok cli['menuconfig'] = False if initramfs_conf['menuconfig'] == 'True': cli['menuconfig'] = True cli['defconfig'] = False if initramfs_conf['defconfig'] == 'True': cli['defconfig'] = True cli['bin-all'] = False if initramfs_conf['bin-all'] == 'True': cli['bin-busybox'] = True cli['bin-luks'] = True cli['bin-lvm2'] = True cli['bin-screen'] = True cli['bin-disklabel'] = True cli['bin-strace'] = True # cli['bin-evms'] = True cli['bin-glibc'] = True cli['bin-libncurses'] = True cli['bin-zlib'] = True cli['bin-dmraid'] = True cli['bin-dropbear'] = True cli['source-all'] = False if initramfs_conf['source-all'] == 'True': cli['source-luks'] = True cli['source-lvm2'] = True cli['source-screen'] = True cli['source-disklabel'] = True cli['source-ttyecho'] = True cli['source-strace'] = True cli['source-dmraid'] = True cli['source-dropbear'] = True cli['bin-luks'] = False if initramfs_conf['bin-luks'] == 'True': cli['bin-luks'] = True cli['source-luks'] = False cli['source-luks'] = False if initramfs_conf['source-luks'] == 'True': cli['source-luks'] = True cli['bin-luks'] = False cli['bin-busybox'] = False if initramfs_conf['bin-busybox'] == 'True': cli['bin-busybox'] = True cli['source-lvm2'] = False if initramfs_conf['source-lvm2'] == 'True': cli['source-lvm2'] = True cli['bin-lvm2'] = False if initramfs_conf['bin-lvm2'] == 'True': cli['bin-lvm2'] = True cli['bin-dmraid'] = False if initramfs_conf['bin-dmraid'] == 'True': cli['bin-dmraid'] = True cli['source-dmraid'] = False if initramfs_conf['source-dmraid'] == 'True': cli['source-dmraid'] = True # cli['iscsi'] = False # if initramfs_conf['iscsi'] == 'True': # cli['iscsi'] = True cli['bin-evms'] = False if initramfs_conf['bin-evms'] == 'True': cli['bin-evms'] = True # cli['mdadm'] = False # if initramfs_conf['mdadm'] == 'True': # cli['mdadm'] = True cli['splash'] = '' if initramfs_conf['splash'] != '': cli['splash'] = initramfs_conf['splash'] cli['sres'] = '' # 1024x768 if initramfs_conf['sres'] != '': cli['sres'] = initramfs_conf['sres'] cli['sinitrd'] = '' # a custom initrd.splash file # cli['firmware'] = '' cli['bin-disklabel'] = False if initramfs_conf['bin-disklabel'] == 'True': cli['bin-disklabel'] = True cli['source-disklabel'] = False if initramfs_conf['source-disklabel'] == 'True': cli['source-disklabel'] = True # cli['unionfs'] = False # if initramfs_conf['unionfs'] == 'True': # cli['unionfs'] = True # cli['aufs'] = False cli['linuxrc'] = '' if initramfs_conf['linuxrc'] != '': cli['linuxrc'] = initramfs_conf['linuxrc'] cli['bin-dropbear'] = False if initramfs_conf['bin-dropbear'] == 'True': cli['bin-dropbear'] = True cli['source-dropbear'] = False if initramfs_conf['source-dropbear'] == 'True': cli['source-dropbear'] = True cli['nomodules'] = False if initramfs_conf['nomodules'] == 'True': cli['nomodules'] = True cli['nocache'] = False if initramfs_conf['nocache'] == 'True': cli['nocache'] = True cli['noboot'] = False if initramfs_conf['noboot'] == 'True': cli['noboot'] = True cli['selinux'] = False # quiet = '2>&1 | tee -a ' + logfile # verbose # quiet = '>>' + logfile + ' 2>&1' # quiet + logfile verbose['std'] = '>>' + cli['logfile'] + ' 2>&1' cli['color'] = True cli['nosaveconfig'] = False # if initramfs_conf['nosaveconfig'] == 'True': # cli['nosaveconfig'] = True cli['hostbin'] = False if initramfs_conf['hostbin'] == 'True': cli['hostbin'] = True cli['bin-glibc'] = False if initramfs_conf['bin-glibc'] == 'True': cli['bin-glibc'] = True cli['bin-libncurses'] = False if initramfs_conf['bin-libncurses'] == 'True': cli['bin-libncurses'] = True cli['bin-zlib'] = False if initramfs_conf['bin-zlib'] == 'True': cli['bin-zlib'] = True # FIXME # # HACK setup default only when using kigen i if not 'tool' in cliopts and not 't' in cliopts: cli['rename'] = '/boot/initramfs-kigen-'+cli['arch']+'-'+cli['KV'] else: cli['rename'] = '' if initramfs_conf['rename'] != '': cli['rename'] = initramfs_conf['rename'] cli['plugin'] = '' if initramfs_conf['plugin'] != '': cli['plugin'] = initramfs_conf['plugin'] cli['rootpasswd'] = '' if initramfs_conf['rootpasswd'] != '': cli['rootpasswd'] = initramfs_conf['rootpasswd'] cli['hostsshkeys'] = False if initramfs_conf['hostsshkeys'] == 'True': cli['hostsshkeys'] = True cli['ssh-pubkeys'] = False if initramfs_conf['ssh-pubkeys'] == 'True': cli['ssh-pubkeys'] = True cli['ssh-pubkeys-file'] = '' if initramfs_conf['ssh-pubkeys-file'] != '': cli['ssh-pubkeys-file'] = initramfs_conf['ssh-pubkeys-file'] cli['source-ttyecho'] = False if initramfs_conf['source-ttyecho'] == 'True': cli['source-ttyecho'] = True cli['keymaps'] = 'all' if initramfs_conf['keymaps'] != '': cli['keymaps'] = initramfs_conf['keymaps'] cli['bin-strace'] = False if initramfs_conf['bin-strace'] == 'True': cli['bin-strace'] = True cli['source-strace'] = False if initramfs_conf['source-strace'] == 'True': cli['source-strace'] =True cli['bin-screen'] = False if initramfs_conf['bin-screen'] == 'True': cli['bin-screen'] = True cli['source-screen'] = False if initramfs_conf['source-screen'] == 'True': cli['source-screen'] = True cli['dynlibs'] = False if initramfs_conf['dynlibs'] == 'True': cli['dynlibs'] = True cli['debugflag'] = False if initramfs_conf['debugflag'] == 'True': cli['debugflag']= True # tools cli['extract'] = '' cli['to'] = '/var/tmp/kigen/extracted-initramfs' cli['compress'] = '' cli['into'] = '/var/tmp/kigen/compressed-initramfs/initramfs_data.cpio.gz' verbose['set'] = False if master_conf['debug'] == 'True': verbose['set'] = True verbose['std'] = '2>&1 | tee -a ' + cli['logfile'] + ' ; test ${PIPESTATUS[0]} -eq 0' verbose['logfile'] = cli['logfile'] # target options for o, a in opts: if o in ("-h", "--help"): usage.print_usage_initramfs(cli, master_conf, initramfs_conf, modules_conf) sys.exit(0) elif o in ("--credits"): usage.print_credits() sys.exit(0) elif o in ("--version"): usage.print_version() sys.exit(0) # have to declare logfile here too elif o in ("--logfile="): cli['logfile'] = a verbose['logfile'] = cli['logfile'] elif o in ("-d", "--debug"): # quiet = '>>' + logfile + ' 2>&1' # logfile # quiet = '2>&1 | tee -a ' + logfile # verbose verbose['std'] = '2>&1 | tee -a ' + cli['logfile'] + ' ; test ${PIPESTATUS[0]} -eq 0' verbose['set'] = True verbose['logfile'] = cli['logfile'] elif o in ("--host-all"): cli['bin-busybox'] = True cli['bin-luks'] = True cli['bin-lvm2'] = True cli['bin-screen'] = True cli['bin-disklabel'] = True cli['bin-strace'] = True # cli['bin-evms'] = True cli['bin-glibc'] = True cli['bin-libncurses'] = True cli['bin-zlib'] = True cli['bin-dmraid'] = True cli['bin-dropbear'] = True elif o in ("--source-all"): cli['source-luks'] = True cli['source-lvm2'] = True cli['source-disklabel'] = True cli['source-screen'] = True cli['source-ttyecho'] = True cli['source-strace'] = True cli['source-dmraid'] = True cli['source-dropbear'] = True elif o in ("--host-disklabel"): cli['bin-disklabel'] = True cli['source-disklabel'] = False elif o in ("--source-disklabel"): cli['bin-disklabel'] = False cli['source-disklabel'] = True elif o in ("--luks"): cli['luks'] = True # FIXME trigger --keymap=all? elif o in ("--host-luks"): cli['bin-luks'] = True cli['source-luks'] = False elif o in ("--source-luks"): cli['source-luks'] = True cli['bin-luks'] = False elif o in ("--source-lvm2"): cli['source-lvm2'] = True cli['bin-lvm2'] = False elif o in ("--host-lvm2"): cli['bin-lvm2'] = True cli['source-lvm2'] = False elif o in ("--host-dmraid"): cli['bin-dmraid'] = True elif o in ("--source-dmraid"): cli['source-dmraid'] = True elif o in ("--dotconfig"): cli['dotconfig'] = a cli['oldconfig'] = True # make sure .config is ok elif o in ("--iscsi"): cli['iscsi'] = True elif o in ("--host-evms"): cli['bin-evms'] = True elif o in ("--mdadm"): cli['mdadm'] = True elif o in ("--mrproper"): cli['mrproper'] = True elif o in ("--menuconfig"): cli['menuconfig'] = True elif o in ("--nooldconfig"): cli['oldconfig'] = False elif o in ("--oldconfig"): cli['oldconfig'] = True elif o in ("--defconfig"): cli['defconfig'] = True elif o in ("--splash"): cli['splash'] = a elif o in ("--firmware"): if os.path.isdir(a): cli['firmware'] = a else: print(("%s is not a directory" % a)) sys.exit(2) elif o in ("--unionfs-fuse"): cli['unionfs'] = True elif o in ("--aufs"): cli['aufs'] = True elif o in ("--linuxrc"): cli['linuxrc'] = a elif o in ("--sres"): cli['sres'] = a elif o in ("--sinitrd"): cli['sinitrd'] = a elif o in ("--nocache"): cli['nocache'] = True elif o in ("--noboot"): cli['noboot'] = True elif o in ("--selinux"): cli['selinux'] = True elif o in ("--host-dropbear"): cli['bin-dropbear'] = True cli['bin-glibc'] = True # dropbear needs glibc cli['bin-libncurses'] = True # dropbear needs libncurses cli['bin-zlib'] = True # dropbear needs zlib elif o in ("--source-dropbear"): cli['source-dropbear'] = True cli['bin-glibc'] = True # dropbear needs glibc cli['bin-libncurses'] = True # dropbear needs libncurses cli['bin-zlib'] = True # dropbear needs zlib elif o in ("--host-glibc"): cli['bin-glibc'] = True elif o in ("--host-libncurses"): cli['bin-libncurses'] = True elif o in ("--host-zlib"): cli['bin-zlib'] = True elif o in ("--rename="): cli['rename'] = a elif o in ("--plugin"): cli['plugin'] = a # a is a list elif o in ("--rootpasswd="): cli['rootpasswd'] = a elif o in ("--hostsshkeys"): cli['hostsshkeys'] = True elif o in ("--ssh-pubkeys"): cli['ssh-pubkeys'] = True elif o in ("--ssh-pubkeys-file="): cli['ssh-pubkeys-file'] = a elif o in("--source-ttyecho"): cli['source-ttyecho'] = True elif o in ("--keymaps"): cli['keymaps'] = a elif o in ("--host-strace"): cli['bin-strace'] = True cli['source-strace'] = False elif o in ("--source-strace"): cli['source-strace'] = True cli['bin-strace'] = False elif o in ("--host-screen"): cli['bin-screen'] = True cli['bin-glibc'] = True # screen needs glibc cli['bin-libncurses'] = True # screen needs libncurses elif o in ("--source-screen"): cli['source-screen'] = True cli['bin-glibc'] = True # screen needs glibc cli['bin-libncurses'] = True # screen needs libncurses elif o in ("--debugflag"): cli['debugflag'] = True elif o in ("--nomodules"): cli['nomodules'] = True elif o in ("--host-busybox"): cli['bin-busybox'] = True elif o in ("--dynlibs"): cli['dynlibs'] = True else: assert False, "uncaught option" # === parsing for the tool target === elif 'tool' in sys.argv or 't' in sys.argv: # we found the tool target # parse accordingly if 'tool' in sys.argv: target = 'tool' cliopts.remove('tool') if 't' in sys.argv: target = 't' cliopts.remove('t') # parse all /etc/kigen/ config files kernel_conf = etcparser.etc_parser_kernel() initramfs_conf, modules_conf, version_conf, url_conf = etcparser.etc_parser_initramfs() try: # parse command line opts, args = getopt(cliopts[1:], "hn", [ \ "help", \ "extract=", \ "to=", \ "compress=", \ "into=", \ "getdotconfig=", \ "rmcache"]) except GetoptError as err: print(str(err)) # "option -a not recognized" usage.print_usage() sys.exit(2) cli['getdotconfig'] = '' cli['extract'] = '' cli['to'] = '/var/tmp/kigen/extracted-initramfs' cli['compress'] = '' cli['into'] = '/var/tmp/kigen/compressed-initramfs/initramfs_data.cpio.gz' cli['rmcache'] = False for o, a in opts: if o in ("-h", "--help"): usage.print_usage_tool(cli) sys.exit(0) elif o in ("--getdotconfig"): cli['getdotconfig'] = a elif o in ("--extract"): cli['extract'] = a elif o in ("--to"): cli['to'] = a elif o in ("--compress"): cli['compress'] = a elif o in ("--into"): cli['into'] = a elif o in ("--rmcache"): cli['rmcache'] = True else: assert False, "uncaught option" if not opts: usage.print_usage_tool(cli) sys.exit(0) # === parsing for NO target === else: try: opts, args = getopt(cliopts[1:], "hn", [\ "help", \ "version", \ "credits"]) except GetoptError as err: print(str(err)) # "option -a not recognized" usage.print_usage() sys.exit(2) # single options for o, a in opts: if o in ("-h", "--help"): usage.print_usage() usage.print_examples() sys.exit(0) elif o in ("--version"): usage.print_version() sys.exit(0) elif o in ("--credits"): usage.print_credits() sys.exit(0) else: assert False, "uncaught option" if target == '': print(stdout.red('error') + ': target not known.') sys.exit(2) ############### # if not 'tool' in cliopts and not 't' in cliopts: # # don't check for kernel version if we use 'kigen tool' # cli['KV'], cli['KNAME'] = utils.misc.get_kernel_version(cli['kerneldir']) # # # exit if kernel dir doesn't exist # if not os.path.isdir(cli['kerneldir']): # print(stdout.red('error') + ': ' + cli['kerneldir'] + ' does not exist.') # sys.exit(2) # # exit if kernel version is not found # if cli['KV'] is 'none': # print(stdout.red('error') + ': ' + cli['kerneldir']+'/Makefile not found') # sys.exit(2) ############### return master_conf, \ kernel_conf, \ modules_conf, \ initramfs_conf, \ version_conf, \ url_conf, \ target, \ cli, \ verbose
options, remainder = getopt.getopt( sys.argv[1:], 'u:p:h:sml', ['username', 'password', 'hashtags', 'stat', 'mine']) for opt, arg in options: if opt in ('-u', '--username'): email_email = arg elif opt in ('-p', '--password'): email_password = arg password_flag = True elif opt in ('-h', '--hashtags'): try: hashtag_flag = True hashtags = arg.split(',') except Exception as ex: usage.print_usage() sys.exit() elif opt in ('-s', '--stat'): stat_flag = True elif opt in ('-m', '--mine'): my_flag = True class TwitterBot: def __init__(self, username, password, likes, retweets, hashtags): self.username = username self.password = password self.likes = 0 self.retweets = 0 self.hashtags = hashtags self.links = []
#write log into log file def write_log(ex): f = open("twitterBot_log.txt", 'a+') f.write('-----------' + str(datetime.datetime.now()) + '----------\n') f.write(str(ex) + '\r\n') f.close() try: from selenium import webdriver from selenium.webdriver.common.keys import Keys except Exception as ex: write_log(ex) usage.print_usage(3) # options input try: options, remainder = getopt.getopt( sys.argv[1:], 'u:k:smih', ['username', 'keywords', 'stat', 'mine', 'info', 'help' ]) # all the options allowed for opt, arg in options: if opt in ('-u', '--username'): email_email = arg elif opt in ('-k', '--keywords'): try: keywords_flag = True keywords = arg.split( ','