· 9 years ago · Mar 31, 2017, 02:56 AM
1PASTEBINnew pastetrends API tools faq
2search...
3
4
5Guest User
6-
7
8Public Pastes
91
109 sec ago
11Untitled
1214 sec ago
13Untitled
14SQL | 20 sec ago
15robux dev
1632 sec ago
17Untitled
1849 sec ago
19Untitled
2052 sec ago
21Untitled
2255 sec ago
23Untitled
241 min ago
25
26SHARE
27TWEET
28
29Untitled
30 A GUEST FEB 17TH, 2017 93 NEVER
31
32Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
33rawdownloadcloneembedreportprint Python 3.63 KB
34import praw
35import time
36import sys
37import sqlite3
38import re
39import datetime
40from selenium import webdriver
41from selenium.webdriver.common.keys import Keys
42
43data = sqlite3.connect('MMA.db')
44cur = data.cursor()
45cur.execute('CREATE TABLE IF NOT EXISTS checked (id)')
46data.commit()
47reddit = praw.Reddit(username='MMAMirrorBot',password='123456',client_id='ezW4oD2FczPp4w',client_secret='625wK17XwEZgN0DmP-lI8XFrgeI',user_agent='A rehosting agent for /r/MMA')
48sites = ['streamable','twitter','oddshot','yout']
49
50class Rehost(object):
51
52 def __init__(self, submission):
53 self.submission = submission
54 self.url = submission.url
55 self.id = submission.id
56
57 def check_url(self):
58 print(self.url)
59 if any(site in str(self.url) for site in sites):
60 print('Matched a site!')
61 return True
62 else:
63 return False
64
65 def check_database(self):
66 cur.execute('SELECT * FROM checked WHERE id=?',[self.id])
67 if not cur.fetchone():
68 return True
69 else:
70 return False
71
72 def submit_to_database(self):
73 cur.execute('INSERT INTO checked VALUES(?)',[self.id])
74 data.commit()
75 print('Saved to database!')
76
77 def upload_video(self):
78 if self.check_url() is True and self.check_database() is True:
79 driver = webdriver.Chrome()
80 driver.get('https://vid.me/')
81 driver.find_element_by_xpath('//*[@id="index"]/div[1]/div/div/div/a[1]').click()
82 time.sleep(2)
83 driver.find_element_by_xpath('//*[@id="uploader-modal"]/form/div/div/div[2]/div[2]/div[1]/input').send_keys(self.url)
84 time.sleep(2)
85 driver.find_element_by_xpath('//*[@id="uploader-modal"]/form/div/div/div[3]/button[1]').click()
86 time.sleep(3)
87 driver.find_element_by_xpath('/html/body/div/div[3]/div/div/div/div/ul/li/div[1]/div[1]/a').click()
88 time.sleep(20)
89 url = str(driver.current_url)
90 driver.quit()
91 return url
92
93class botResponse(object):
94
95 def __init__(self, submission):
96 self.submission = submission
97 self.created = submission.created_utc
98 self.no_response = time.mktime(datetime.datetime.now().timetuple()) - (24*60*60)
99 self.title = submission.title
100 self.permalink = submission.permalink
101 self.author = submission.author.name
102
103 def return_format(self):
104 try:
105 post_url = Rehost(self.submission).upload_video()
106 if post_url is None:
107 raise Exception('No url')
108 preface = 'In case this video is removed or lost, I have mirrored it\n\n'
109 body = '[{} - Mirrored]({})'.format(re.sub('\s+', ' ',str(self.title)), post_url)
110 disclaimer = '\n\n---\n\n^^I ^^am ^^a ^^bot ^^created ^^by ^^[/u/iNeverQuiteWas](/u/iNeverQuiteWas), ^^please ^^contact ^^him ^^if ^^you ^^have ^^any ^^questions ^^or ^^would ^^like ^^a ^^bot ^^of ^^your ^^own'
111 response = preface+body+disclaimer
112 return response
113 except:
114 raise Exception
115
116 def check_no_response(self):
117 if self.created - int(self.no_response) > 0:
118 return True
119 else:
120 return False
121
122 def reply_to_submission(self):
123 print(self.author)
124 if self.check_no_response() is True:
125 print("Replying...")
126 response = self.return_format()
127 comment = self.submission.reply(response)
128 comment.mod.distinguish()
129 print('Replied to /u/{}'.format(self.author))
130 else:
131 print('Passing because later than a day old')
132
133 def run(self):
134 self.reply_to_submission()
135 self.set_sticky()
136
137def main():
138 while True:
139 print('Starting set...')
140 for submission in reddit.subreddit('MMA').new(limit=100):
141 try:
142 botResponse(submission).run()
143 except Exception as e:
144 time.sleep(2)
145 if e is KeyboardInterrupt:
146 sys.exit()
147 else:
148 print(e)
149 pass
150 print('Finished set...')
151 time.sleep(60*2)
152
153if __name__ == '__main__':
154 main()
155RAW Paste Data
156
157import praw
158import time
159import sys
160import sqlite3
161import re
162import datetime
163from selenium import webdriver
164from selenium.webdriver.common.keys import Keys
165
166data = sqlite3.connect('MMA.db')
167cur = data.cursor()
168cur.execute('CREATE TABLE IF NOT EXISTS checked (id)')
169data.commit()
170reddit = praw.Reddit(username='MMAMirrorBot',password='123456',client_id='ezW4oD2FczPp4w',client_secret='625wK17XwEZgN0DmP-lI8XFrgeI',user_agent='A rehosting agent for /r/MMA')
171sites = ['streamable','twitter','oddshot','yout']
172
173class Rehost(object):
174
175 def __init__(self, submission):
176 self.submission = submission
177 self.url = submission.url
178 self.id = submission.id
179
180 def check_url(self):
181 print(self.url)
182 if any(site in str(self.url) for site in sites):
183 print('Matched a site!')
184 return True
185 else:
186 return False
187
188 def check_database(self):
189 cur.execute('SELECT * FROM checked WHERE id=?',[self.id])
190 if not cur.fetchone():
191 return True
192 else:
193 return False
194
195 def submit_to_database(self):
196 cur.execute('INSERT INTO checked VALUES(?)',[self.id])
197 data.commit()
198 print('Saved to database!')
199
200 def upload_video(self):
201 try:
202 if self.check_url() is True and self.check_database() is True:
203 driver = webdriver.Chrome()
204 driver.get('https://vid.me/')
205 driver.find_element_by_xpath('//*[@id="index"]/div[1]/div/div/div/a[1]').click()
206 time.sleep(2)
207 driver.find_element_by_xpath('//*[@id="uploader-modal"]/form/div/div/div[2]/div[2]/div[1]/input').send_keys(self.url)
208 time.sleep(2)
209 driver.find_element_by_xpath('//*[@id="uploader-modal"]/form/div/div/div[3]/button[1]').click()
210 time.sleep(3)
211 driver.find_element_by_xpath('/html/body/div/div[3]/div/div/div/div/ul/li/div[1]/div[1]/a').click()
212 time.sleep(20)
213 url = str(driver.current_url)
214 driver.quit()
215 return url
216 except:
217 driver.quit()
218 return None
219
220class botResponse(object):
221
222 def __init__(self, submission):
223 self.submission = submission
224 self.created = submission.created_utc
225 self.no_response = time.mktime(datetime.datetime.now().timetuple()) - (24*60*60)
226 self.title = submission.title
227 self.permalink = submission.permalink
228 self.author = submission.author.name
229
230 def return_format(self):
231 try:
232 post_url = Rehost(self.submission).upload_video()
233 if post_url is None:
234 raise Exception('No url')
235 preface = 'In case this video is removed or lost, I have mirrored it\n\n'
236 body = '[{} - Mirrored]({})'.format(re.sub('\s+', ' ',str(self.title)), post_url)
237 disclaimer = '\n\n---\n\n^^I ^^am ^^a ^^bot ^^created ^^by ^^[/u/iNeverQuiteWas](/u/iNeverQuiteWas), ^^please ^^contact ^^him ^^if ^^you ^^have ^^any ^^questions ^^or ^^would ^^like ^^a ^^bot ^^of ^^your ^^own'
238 response = preface+body+disclaimer
239 return response
240 except:
241 raise Exception
242
243 def check_no_response(self):
244 if self.created - int(self.no_response) > 0:
245 return True
246 else:
247 return False
248
249 def reply_to_submission(self):
250 print(self.author)
251 if self.check_no_response() is True:
252 print("Replying...")
253 response = self.return_format()
254 comment = self.submission.reply(response)
255 comment.mod.distinguish()
256 print('Replied to /u/{}'.format(self.author))
257 else:
258 print('Passing because later than a day old')
259
260 def run(self):
261 self.reply_to_submission()
262 self.set_sticky()
263
264def main():
265 while True:
266 print('Starting set...')
267 for submission in reddit.subreddit('MMA').new(limit=100):
268 try:
269 botResponse(submission).run()
270 except Exception as e:
271 time.sleep(2)
272 if e is KeyboardInterrupt:
273 sys.exit()
274 else:
275 print(e)
276 pass
277 print('Finished set...')
278 time.sleep(60*2)
279
280if __name__ == '__main__':
281 main()
282
283
284create new paste / dealsnew! / api / trends / syntax languages / faq / tools / privacy / cookies / contact / dmca / scraping / go
285Site design & logo © 2016 Pastebin; user contributions (pastes) licensed under cc by-sa 3.0 -- Dedicated Server Hosting by Steadfast Top