def on_data(self, data): tweet_data = json.loads(data) if not tweet_data['text'].startswith('RT'): user_data = tweet_data["user"] # print(tweet_data) tweets_id = (tweet_data["id"]) tweet_checker = lambda x: (x["extended_tweet"][ "full_text"]) if "extended_tweet" in x else x["text"] tweet_string = tweet_checker(tweet_data) tweet_text = str(tweet_string) created_at = (tweet_data["created_at"]) location = (user_data["location"]) coordinates = (tweet_data["coordinates"]) user_followers = (user_data["followers_count"]) friends_no = (user_data["friends_count"]) senti = str(TextBlob(tweet_text).sentiment) tweet = tweets_id, tweet_text, created_at, location, coordinates, user_followers, friends_no, senti if self.tweet_counter >= self.tweet_stop: ui.info_2(ui.blue, "{} Tweets added!".format(self.tweet_stop), ui.check) number_rows() # print("Done! {} tweets added!".format(self.tweet_counter)) return False else: # Locks the db while fetching... # //TODO: queue of list of tweets so the db does not remain locked while fetch_tweets() insert_tweet(tweet, self.table_name) self.tweet_counter += 1 ui.info_progress("Fetching...", self.tweet_counter, self.tweet_stop)
def ensure_merge_request(self): merge_request = self.find_merge_request() if merge_request: ui.info_2("Found existing merge request: !%s" % merge_request["iid"]) return merge_request else: return self.create_merge_request()
def sync_repo_to_ref(repo_path, ref): ui.info_2("Resetting to", ref) status = tsrc.git.get_status(repo_path) if status.dirty: raise tsrc.Error("%s dirty, skipping") try: tsrc.git.run_git(repo_path, "reset", "--hard", ref) except tsrc.Error: raise tsrc.Error("updating ref failed")
def push(self): ui.info_2("Running git push") cmd = [ "push", "-u", "origin", "%s:%s" % (self.source_branch, self.source_branch) ] if self.args.force: cmd.append("--force") tsrc.git.run_git(self.repo_path, *cmd)
def update(self): ui.info_2("Updating manifest") if not self.clone_path.exists(): message = "Could not find manifest in {}. " message += "Did you run `tsrc init` ?" raise tsrc.Error(message.format(self.clone_path)) cmd = ("fetch", "--prune", "origin") tsrc.git.run_git(self.clone_path, *cmd) cmd = ("reset", "--hard", "@{u}") tsrc.git.run_git(self.clone_path, *cmd)
def accept_merge_request(self, merge_request): project_id = merge_request["project_id"] merge_request_iid = merge_request["iid"] ui.info_2("Merging when build succeeds", ui.ellipsis, end="") url = "/projects/%s/merge_requests/%s/merge" % (project_id, merge_request_iid) data = { "merge_when_pipeline_succeeds": True, } self.make_request("PUT", url, data=data) ui.info("done", ui.check)
def create_merge_request(self, project_id, source_branch, *, title, target_branch="master"): ui.info_2("Creating merge request", ui.ellipsis, end="") url = "/projects/%i/merge_requests" % project_id data = { "source_branch": source_branch, "target_branch": target_branch, "title": title, "project_id": project_id, } result = self.make_request("POST", url, data=data) ui.info("done", ui.check) return result
def process(self, repo): full_path = self.workspace.joinpath(repo.src) try: _, old_url = tsrc.git.run_git(full_path, "remote", "get-url", "origin", raises=False) if old_url != repo.url: ui.info_2(repo.src, old_url, "->", repo.url) tsrc.git.run_git(full_path, "remote", "set-url", "origin", repo.url) except Exception: raise tsrc.Error(repo.src, ":", "Failed to set remote url to %s" % repo.url)
def process(self, repo): ui.info(repo.src) repo_path = self.workspace.joinpath(repo.src) parent, name = repo_path.splitpath() parent.makedirs_p() try: tsrc.git.run_git(parent, "clone", repo.url, "--branch", repo.branch, name) except tsrc.Error: raise tsrc.Error("Cloning failed") ref = repo.fixed_ref if ref: ui.info_2("Resetting", repo.src, "to", ref) try: tsrc.git.run_git(repo_path, "reset", "--hard", ref) except tsrc.Error: raise tsrc.Error("Resetting to", ref, "failed")
def handle_merge_request(self): assignee = self.handle_assignee() if assignee: ui.info_2("Assigning to", assignee["name"]) merge_request = self.ensure_merge_request() title = self.handle_title(merge_request) params = { "title": title, "target_branch": self.target_branch, "remove_source_branch": True, } if assignee: params["assignee_id"] = assignee["id"] self.gl_helper.update_merge_request(merge_request, **params) if self.args.accept: self.gl_helper.accept_merge_request(merge_request) ui.info(ui.green, "::", ui.reset, "See merge request at", merge_request["web_url"])
def ask_table(db_file=TWEETS_DB, conn=create_conection(), table_name=TABLE_NAME): """Default table or new table. Checks if table exists, creates one if not with name from user and calls user_ans_tweets(). :param db_file: DEFAULT database :param conn: creates connection() :param table_name: name of table """ def ploting(tweets_db=TWEETS_DB, csv_file=CSV_FILE): table_name = MyStreamListener.table_name plot_question = ui.ask_yes_no("Plot?", default=True) if plot_question: ui.info(ui.green, "Populating csv file with {}".format(table_name)) q_four.db_into_csv(TWEETS_DB, CSV_FILE, table_name) ui.info_3("Ploting...") q_four.frecuency() q_four.senti() else: ui.info(ui.turquoise, "Program Finished") exit() tables_list = list() conn = create_conection() cur = conn.cursor() cur.execute("SELECT name FROM sqlite_master") for table in cur: tables = str(table).strip('(').strip(')').strip(',').strip("'") tables_list.append(tables) if "trump" in tables_list: ui.info_1(ui.yellow, ui.bold, "DEFAULT TABLE FOUND! =>", ui.blue, ui.standout, "'trump'") new_db_ans = ui.ask_yes_no("Add tweets to table 'trump'?", default=True) if new_db_ans: ui.warning("Creating database (If it doesn't exist)") create_conection() ui.info_2(ui.green, "Accessing Database") MyStreamListener.table_name = TABLE_NAME user_ans_tweets() ploting() else: choices = ["Create New Table", "Load table", "Plot", "Quit"] new = ui.ask_choice("Select: ", choices) if new == "Create New Table": ui.warning("Tables with the same name will not be created") new_table_name = ui.ask_string("Enter new table name:") new_table_name = new_table_name.lower() new_table_name = new_table_name.replace(" ", "_") ui.info("Table name with format:", ui.blue, new_table_name) create_ans = ui.ask_yes_no("Create?") if create_ans: tweets_table_create(create_conection(), TWEETS_DB, new_table_name) insert_new_tbl = ui.ask_yes_no( "Insert new tweets into {}?".format(new_table_name)) if insert_new_tbl: MyStreamListener.table_name = new_table_name user_ans_tweets() ploting() else: ui.info(ui.bold, ("Program Finished")) else: ui.info(ui.bols, "Program Finished") elif new == "Load table": new_table_name = ui.ask_choice("Select Table to load:", tables_list) MyStreamListener.table_name = new_table_name user_ans_tweets() ploting() elif new == "Plot": new_table_name = ui.ask_choice("Select Table to plot:", tables_list) MyStreamListener.table_name = new_table_name ploting() elif new == "Quit": ui.warning("Program Finished") exit()
def print_results(target_objs): for target in target_objs: ui.info_section("\n", ui.bold, "Result", ui.reset, ui.yellow, target.email) if target.pwnd: ui.info_2("breached", ui.check) ui.info(ui.teal, "---") ui.info("Breaches found", ui.darkred, "HIBP:", ui.teal, len(target.services["hibp"])) if target.services["weleakinfo"]: ui.info("Breaches found", ui.darkred, "WeLeakInfo:", ui.teal, len(target.services["weleakinfo"])) if target.services["snusbase"]: ui.info("Breaches found", ui.darkred, "Snusbase:", ui.teal, len(target.services["snusbase"])) if target.breachcomp_passw: ui.info("Breaches found", ui.darkred, "breachcompilation:", ui.teal, len(target.breachcomp_passw)) ui.debug("Breaches/Dumps HIBP:", ui.lightgray, target.services["hibp"]) ui.debug("Breaches/Dumps WeLeakInfo:", ui.lightgray, target.services["weleakinfo"]) ui.debug("Breaches/Dumps Snusbase:", ui.lightgray, target.services["snusbase"]) else: ui.info_2("not breached", ui.cross) if target.related_emails: ui.info("Related emails found", ui.darkred, "hunter.io:", ui.teal, target.related_emails) ui.info(ui.teal, "---") ui.info("Target hostname:", ui.teal, target.hostname) if target.ip: ui.info("Target domain IP:", ui.teal, target.ip) if target.rev_dns: ui.info("Target reverse DNS:", ui.teal, target.rev_dns) if target.rev_ports: ui.info("Open ports:", ui.teal, *target.rev_ports) if len(target.hunterio_mails) != 0: ui.info(ui.teal, "---") ui.info(ui.check, ui.darkred, "hunter.io", ui.reset, "best related emails:", ui.lightgray, "\n", target.hunterio_mails) if target.snusbase_passw: ui.info(ui.teal, "---") ui.info(ui.check, ui.darkred, "Snusbase:", ui.reset, "Passwords found", ui.teal, len(target.snusbase_passw)) if target.snusbase_hash_salt: ui.info(ui.check, ui.darkred, "Snusbase:", ui.reset, "Hash/salts found", ui.teal, len(target.snusbase_hash_salt)) if target.snusbase_hash_salt: ui.info(ui.darkred, "Snusbase", ui.reset, "passwords:", ui.teal, target.snusbase_passw) if target.snusbase_hash_salt: ui.info(ui.darkred, "Snusbase", ui.reset, "hash/salt:", ui.lightgray, target.snusbase_hash_salt) ui.info("\n") if target.breachcomp_passw: ui.info(ui.teal, "---") ui.info(ui.darkred, "breachcompilation", ui.reset, "passwords:", ui.teal, ui.teal, *target.breachcomp_passw) ui.info("-------------------------------") if target.pastebin_urls: ui.info(ui.teal, "---") ui.info(ui.check, ui.darkred, "Pastebin", ui.reset, "Urls where first emails is related in:", ui.lightgray, "\n", target.pastebin_urls)
def fetch_emails(target): e = re.findall(r"[\w\.-]+@[\w\.-]+", target) if e: ui.info_2(e[0]) return e[0] return None
import ui import os import subprocess tools = [ 'compiler', 'diff', 'memcheck', 'backup-server', 'backup-client', 'quit' ] while 1: out = ui.ask_choice('Co zainstalować?', tools) if out == 'quit': exit() if out == 'compiler': ui.info_2('installing') os.system( f'bash -c "cd { os.path.dirname(os.path.abspath(__file__)) }/compiler++ && source compile.sh" ' ) #subprocess.run(['sh','./compiler++/compile.sh'],) ui.info_2( 'Zainstalowano - od teraz można w terminalu uzyć komendy c [nazwaprogramu]' ) if out == 'backup-client': ui.info_2('installing') os.system( f'bash -c "cd { os.path.dirname(os.path.abspath(__file__)) }/backup/client"' ) ip = ui.ask_string( 'podaj ip serwera backupowego, dla lokalnego wpisz 127.0.0.1') port = ui.ask_string('podaj port serwera backupowego') pswd = ui.ask_password( 'podaj haslo do serwera backupowego (ustawisz je przy instalacji serwera)'
def reset(repo, ref): ui.info_2("Resetting", repo, "to", ref) run_git(repo, "reset", "--hard", ref)
def run(self): ui.info_2(self.name) rc = subprocess.call(self.cmd) self.ok = (rc == 0)