<commit_before>#!/usr/bin/env python

import string
import ctypes
import os
from threading  import Thread
from time import sleep
import re

# For headless browsing.  Life made easy.
from selenium import webdriver

from selenium.common.exceptions import NoSuchElementException

# Tkinter main
from Tkinter import Tk, Frame
# Tkinter GUI widgets
from Tkinter import Button, Text, Entry, Label, Toplevel, Spinbox
# Tkinter alignment options
from Tkinter import LEFT, RIGHT, BOTH, CENTER
# Tkinter directions W=West, E=East, etc...
from Tkinter import N, NE, E, SE, S, SW, W, NW
# Tkinter state options
from Tkinter import DISABLED, NORMAL
# Tkinter position options
from Tkinter import END

# Style?  Idk, but this is cool
from ttk import Style

class Application(Frame):
    threadRunning = False

    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.parent = parent
        self.initUI()

    def threadded(self,*config):
        self.threadRunning = True

        debugger = config[5]

        self.addDebug(debugger,"Posting thread started")

        if config[0] == "":
            self.addDebug(debugger,"  - No username")
            self.addDebug(debugger,"Posting thread finished")
            self.threadRunning = False
            return
        if config[1] == "":
            self.addDebug(debugger,"  - No password")
            self.addDebug(debugger,"Posting thread finished")
            self.threadRunning = False
            return

        self.addDebug(debugger,"  - Configuration:")
        self.addDebug(debugger,"      Output Path: %s" % (config[3]))
        self.addDebug(debugger,"      # of Posts: %d" % (int(config[4])))

        driver = webdriver.PhantomJS('phantomjs')
        self.addDebug(debugger,"  - Driver successfully loaded")

        driver.get('https://accounts.google.com/ServiceLogin?service=oz&continue=https://plus.google.com/')
        self.addDebug(debugger,"  - Successfully navigated to G+ login page")
        
        driver.find_element_by_id("Email").send_keys(config[0])
        driver.find_element_by_id("Passwd").send_keys(config[1])
        driver.find_element_by_name("signIn").click()
        self.addDebug(debugger,"  - Attempting to log in")
        
        if driver.current_url != "https://plus.google.com/":
            self.addDebug(debugger,"  - Incorrect username/password")
        else:
            self.addDebug(debugger,"  - Successfully logged in")

            profileLink = ""

            self.addDebug(debugger,"  - Searching for profile link")
            for element in driver.find_elements_by_tag_name("a"):
                if element.get_attribute("aria-label") == "Profile":
                    m = re.search('/plus.google.com/(.+)', element.get_attribute("href"))
                    if m:
                        profileLink = m.group(1)
                    self.addDebug(debugger,"  - %s" % (profileLink))
                    break

            for x in range(0,int(config[4])):
                tempHolder = driver.find_elements_by_tag_name("body")

                self.addDebug(debugger,"  - Searching for text input")
                for element in driver.find_elements_by_tag_name("div"):
                    if element.get_attribute("guidedhelpid") == "sharebox_textarea":
                        element.click()
                        break

                sleep(5)

                for element in driver.find_elements_by_tag_name("div"):
                    if element.get_attribute("guidedhelpid") == "sharebox_editor":
                        tempHolder = element
                        break

                for element in tempHolder.find_elements_by_tag_name("div"):
                    if element.get_attribute("role") == "textbox":
                        self.addDebug(debugger, "  - Found it!")
                        self.addDebug(debugger,"  - Inputting Text")
                        element.send_keys(config[2])
                        break

                self.addDebug(debugger,"  - Searching for submit button")
                for element in driver.find_elements_by_tag_name("div"):
                    if element.get_attribute("guidedhelpid") == "shareboxcontrols":
                        tempHolder = element
                        break

                for element in tempHolder.find_elements_by_tag_name("div"):
                    if element.get_attribute("guidedhelpid") == "sharebutton":
                        self.addDebug(debugger, "  - Found it!")
                        element.click()
                        break

                sleep(5)

                driver.get("https://plus.google.com/" + profileLink + "/posts")
                self.addDebug(debugger,"  - Searching for post")

                for element in driver.find_elements_by_tag_name("a"):
                    try: 
                        if (profileLink + "/posts/") in element.get_attribute("href"):
                            self.addDebug(debugger,"  - %s" % (element.get_attribute("href")))
                            break
                    except:
                        continue

                self.addDebug(debugger,"  - Waiting 5 seconds before another post")
                sleep(5)
        
        self.addDebug(debugger,"Posting thread finished")
        self.threadRunning = False

    def addDebug(self,parent,text):
        parent.insert('end',"%s\n" % (text))
        parent.see(END)

    def doPosting(self,me,debugLogger,username,password,message,output,num):
        if self.threadRunning != True:
            settings = [
                username,
                password,
                message,
                output,<commit_msg>Writes to file<commit_after>#!/usr/bin/env python

import string
import ctypes
import os
from os import path
from threading  import Thread
from time import sleep
import re

# For headless browsing.  Life made easy.
from selenium import webdriver

from selenium.common.exceptions import NoSuchElementException

# Tkinter main
from Tkinter import Tk, Frame
# Tkinter GUI widgets
from Tkinter import Button, Text, Entry, Label, Toplevel, Spinbox
# Tkinter alignment options
from Tkinter import LEFT, RIGHT, BOTH, CENTER
# Tkinter directions W=West, E=East, etc...
from Tkinter import N, NE, E, SE, S, SW, W, NW
# Tkinter state options
from Tkinter import DISABLED, NORMAL
# Tkinter position options
from Tkinter import END

# Style?  Idk, but this is cool
from ttk import Style

class Application(Frame):
    threadRunning = False

    def __init__(self, parent):
        Frame.__init__(self, parent)
        self.parent = parent
        self.initUI()

    def threadded(self,*config):
        self.threadRunning = True

        debugger = config[5]

        self.addDebug(debugger,"Posting thread started")

        if config[0] == "":
            self.addDebug(debugger,"  - No username")
            self.addDebug(debugger,"Posting thread finished")
            self.threadRunning = False
            return
        if config[1] == "":
            self.addDebug(debugger,"  - No password")
            self.addDebug(debugger,"Posting thread finished")
            self.threadRunning = False
            return

        f = open(config[3], "a")

        self.addDebug(debugger,"  - Configuration:")
        self.addDebug(debugger,"      Output Path: %s" % (config[3]))
        self.addDebug(debugger,"      # of Posts: %d" % (int(config[4])))

        driver = webdriver.PhantomJS('phantomjs')
        self.addDebug(debugger,"  - Driver successfully loaded")

        driver.get('https://accounts.google.com/ServiceLogin?service=oz&continue=https://plus.google.com/')
        self.addDebug(debugger,"  - Successfully navigated to G+ login page")
        
        driver.find_element_by_id("Email").send_keys(config[0])
        driver.find_element_by_id("Passwd").send_keys(config[1])
        driver.find_element_by_name("signIn").click()
        self.addDebug(debugger,"  - Attempting to log in")
        
        if driver.current_url != "https://plus.google.com/":
            self.addDebug(debugger,"  - Incorrect username/password")
        else:
            self.addDebug(debugger,"  - Successfully logged in")

            profileLink = ""

            self.addDebug(debugger,"  - Searching for profile link")
            for element in driver.find_elements_by_tag_name("a"):
                if element.get_attribute("aria-label") == "Profile":
                    m = re.search('/plus.google.com/(.+)', element.get_attribute("href"))
                    if m:
                        profileLink = m.group(1)
                    self.addDebug(debugger,"  - %s" % (profileLink))
                    break

            for x in range(0,int(config[4])):
                tempHolder = driver.find_elements_by_tag_name("body")

                self.addDebug(debugger,"  - Searching for text input")
                for element in driver.find_elements_by_tag_name("div"):
                    if element.get_attribute("guidedhelpid") == "sharebox_textarea":
                        element.click()
                        break

                sleep(5)

                for element in driver.find_elements_by_tag_name("div"):
                    if element.get_attribute("guidedhelpid") == "sharebox_editor":
                        tempHolder = element
                        break

                for element in tempHolder.find_elements_by_tag_name("div"):
                    if element.get_attribute("role") == "textbox":
                        self.addDebug(debugger, "  - Found it!")
                        self.addDebug(debugger,"  - Inputting Text")
                        element.send_keys(config[2])
                        break

                self.addDebug(debugger,"  - Searching for submit button")
                for element in driver.find_elements_by_tag_name("div"):
                    if element.get_attribute("guidedhelpid") == "shareboxcontrols":
                        tempHolder = element
                        break

                for element in tempHolder.find_elements_by_tag_name("div"):
                    if element.get_attribute("guidedhelpid") == "sharebutton":
                        self.addDebug(debugger, "  - Found it!")
                        element.click()
                        break

                sleep(5)

                driver.get("https://plus.google.com/" + profileLink + "/posts")
                self.addDebug(debugger,"  - Searching for post")

                for element in driver.find_elements_by_tag_name("a"):
                    try: 
                        if (profileLink + "/posts/") in element.get_attribute("href"):
                            f.write(element.get_attribute("href"))
                            self.addDebug(debugger,"  - Found URL, saving")
                            break
                    except:
                        continue

                self.addDebug(debugger,"  - Waiting 5 seconds before another post")
                sleep(5)
        
        self.addDebug(debugger,"Posting thread finished")
        self.threadRunning = False
        f.close()

    def addDebug(self,parent,text):
        parent.insert('end',"%s\n" % (text))
        parent.see(END)

    def doPosting(self,me,debugLogger,username,password,message,output,num):
        if self.threadRunning != True:
            settings = [
                username,
                password,
                message,
                output,
{'fraction_non_alphanumeric': 0.1042155584528466, 'fraction_numerical': 0.0026944806605823557, 'mean_word_length': 1.827027027027027, 'pattern_counts': {'":': 18, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 8, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1702366', 'n_tokens_mistral': 3171, 'n_tokens_neox': 3001, 'n_words': 689}