-
Notifications
You must be signed in to change notification settings - Fork 1
/
RedditBot.py
98 lines (68 loc) · 3.77 KB
/
RedditBot.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
from selenium import webdriver
from selenium.webdriver.firefox.options import Options
from datetime import datetime
import time
import schedule
from helpers import get_config
config = get_config()
forumlist = config.get('forum_list')
options = webdriver.FirefoxOptions()
options.set_preference("dom.push.enabled", False)
driver = webdriver.Firefox(firefox_options=options)
time.sleep(3)
driver.get('https://www.reddit.com/login/?dest=https%3A%2F%2Fwww.reddit.com%2F')
username = config.get('username')
entername = driver.find_element_by_id("loginUsername")
entername.send_keys(username)
time.sleep(2)
password = config.get('password')
enterpw = driver.find_element_by_id("loginPassword")
enterpw.send_keys(password)
time.sleep(1)
p_loginl = driver.find_element_by_xpath("/html/body/div/main/div[1]/div/div[2]/form/fieldset[5]/button").click()
time.sleep(20)
def postjob():
for x in forumlist:
gopost = driver.find_element_by_css_selector("button._1x6pySZ2CoUnAfsFhGe7J1").click()
#gopost = driver.find_element_by_xpath("/html/body/div[1]/div/div[2]/div[1]/header/div/div[2]/div[2]/div/div[1]/span[3]/button").click()
time.sleep(10)
enterforum = driver.find_element_by_css_selector("._1MHSX9NVr4C2QxH2dMcg4M")
#enterforum = driver.find_element_by_xpath("/html/body/div[1]/div/div[2]/div[2]/div/div/div/div[2]/div[3]/div[1]/div[2]/div[2]/div/div/div[1]/input")
enterforum.clear()
enterforum.send_keys(x)
time.sleep(3)
jstitletext = """
var elm = arguments[0], txt = arguments[1];
elm.value += txt;
elm.dispatchEvent(new Event('change'));
"""
entertitletext = driver.find_element_by_css_selector("._2wyvfFW3oNcCs5GVkmcJ8z > textarea:nth-child(1)")
titletext = config.get('title_text')
driver.execute_script(jstitletext, entertitletext, titletext)
entertitletext.clear() #Title was being entered twice so this clears first entry
entertitletext.send_keys(titletext)
time.sleep(1)
jsmaintext = """
var elm = arguments[0], txt = arguments[1];
elm.value += txt;
elm.dispatchEvent(new Event('change'));
"""
entermaintext = driver.find_element_by_css_selector("#SHORTCUT_FOCUSABLE_DIV > div:nth-child(4) > div > div > div > div._3ozFtOe6WpJEMUtxDOIvtU > div._1vyLCp-v-tE5QvZovwrASa > div._1OVBBWLtHoSPfGCRaPzpTf._3nSp9cdBpqL13CqjdMr2L_._2udhMC-jldHp_EpAuBeSR1.PaJBYLqPf_Gie2aZntVQ7 > div.HOFZo2X7Fr6JVBztpsByj > div._3w_665DK_NH7yIsRMuZkqB > div._1zq6UabIEJJ-z9grsiCJY7 > div:nth-child(2) > div > div > div._2baJGEALPiEMZpWB2iWQs7 > div > div:nth-child(1) > div > div > div")
#entermaintext = driver.find_element_by_xpath("/html/body/div[1]/div/div[2]/div[2]/div/div/div/div[2]/div[3]/div[1]/div[2]/div[3]/div[2]/div[2]/div/div/div[3]/div/div[1]/div/div/div/div/div/div[1]/div/span/span")
maintext = config.get('main_text')
driver.execute_script(jstitletext, entermaintext, maintext)
entermaintext.send_keys(maintext)
time.sleep(2)
time.sleep(1)
p_submit = driver.find_element_by_css_selector("._18Bo5Wuo3tMV-RDB8-kh8Z").click()
#p_submit = driver.find_element_by_xpath("/html/body/div[1]/div/div[2]/div[2]/div/div/div/div[2]/div[3]/div[1]/div[2]/div[3]/div[3]/div[2]/div/div[1]/button").click()
now = datetime.now().time()
time.sleep(10)
urlrn = driver.current_url
if urlrn != "https://www.reddit.com/submit":
print("Successfully posted to ", x ,"at", now,".")
time.sleep(40)
schedule.every(30).minutes.do(postjob)
while True:
schedule.run_pending()
time.sleep(1)