-
Notifications
You must be signed in to change notification settings - Fork 0
/
rgdsn.py
723 lines (451 loc) · 10.4 KB
/
rgdsn.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
# -*- coding: utf-8 -*-
# <nbformat>3.0</nbformat>
# <markdowncell>
# <h1>Reddit Gets Drawn Snatch Script</h1>
#
# Creates the website redditgetsdrawnrecentreference. It contains the 25 most recent posts on r/redditgetsdrawn. title, image url, and username
#
# TODO:
# Contains artwork replies to each thread
#
# This is a Python script that takes data from reddit and posts it to another subreddit. It also creates a html file with the images embed into. The images are the most recent 25 on r/redditgetsdrawn.
#
# The script returns the comments from the most recent 25 posts along with the comments of comments.
#
# Pandas is used to append everything into a series and DataFrame.
# The pandas allows youto easily append these together.
#
# get all artwork and append into reference image ->
# artwork.
#
# Generate sites again.
#
# <markdowncell>
# RedditGetsDrawn Snatch
#
# This is a Python script that takes data from reddit and posts it to another subreddit. It also creates a html file with the images embed into. The images are the most recent 25 on r/redditgetsdrawn.
#
#
# <markdowncell>
#
# TODO
#
# submit art to users via website
#
# fix image sizes (need to scale down to 550px)
#
# Save to server rather than imgur
#
# Archieve, snapshots of rgd
#
# more artcontrol
#
# itwillbemine comments to html - currently being saved in contact
#
# work on css, div up page, title, side, body, fo
#
# update twitter with ONE IMAGE and announce that the list has been updated.
#
# write blog post and submits to artcontroldrawsyou/blog
#
# gets sticked post on reddit
#
# delete about/contact page and have on all same page. can still have link to blog.
# about
# contact etc... along the top.
# other sections
#
# post images to blog for archieve - save body to wcmckee.com/blog - md format?
#
# nikola install - build site.
#
# cronjob to update site ever ?? hours? 4?
#
# photos section: latest 25 photos submitted to redditgetsdrawn.
# art section: latest 25 art submitted to redditgetsdrawn.
#
# cleanup code
#
# import pandas into it and removed things i dont need like dominate
# <codecell>
import os
import random
import requests
from bs4 import BeautifulSoup
import re
import json
import time
import praw
import dominate
from dominate.tags import *
from time import gmtime, strftime
#import nose
#import unittest
import numpy as np
import pandas as pd
from pandas import *
# <codecell>
chdira = ('/home/wcmckee/artcontroldrawsyou')
os.chdir(chdira)
# <codecell>
r = praw.Reddit(user_agent='rgdsnatch')
# <codecell>
#r.login('artcontrol', 'taylor123vag!')
# <codecell>
rd = r.get_subreddit('redditgetsdrawn')
# <codecell>
subz = rd.get_hot().next()
istit = (subz.title)
istxt = (subz.selftext_html)
istick = (subz.stickied)
rdnewz = rd.get_new()
rdnew = []
# <codecell>
reddraw = praw.Reddit(user_agent='rgdsnatch')
# <codecell>
getrddraw = reddraw.get_subreddit('redditgetsdrawn')
# <codecell>
decict = dict()
# <codecell>
subz = getrddraw.get_new()
# <codecell>
#class TestRedditFunction(unittest.TestCase):
# def setUp(self):
# self.seq = reddraw.get_subreddit('redditgetsdrawn')
# def testredit(self):
# drawnew('redditgetsdrawn')
# <codecell>
def drawnew(subred):
getrdraw = reddraw.get_subreddit(subred)
return getrdraw
def apred(deciz):
return (deciz)
# <codecell>
apred('omg')
# <codecell>
rdrws = drawnew('redditgetsdrawn')
# <codecell>
rtohr = rdrws.get_controversial_from_all()
# <codecell>
for imgz in rtohr:
#print imgz.selftext
print imgz.num_comments
# <codecell>
rdnewz = getrddraw.get_new()
# <codecell>
rdnew = []
# <codecell>
rdnew
# <codecell>
for uz in rdnewz:
#print uz
rdnew.append(uz)
# <codecell>
datelis = []
refdic = {}
rgdef = dict()
comdefz = []
# <codecell>
for rdz in rdnew:
print rdz.name
print rdz.title
print rdz.url
print rdz.author
print rdz.secure_media
print rdz.num_comments
print rdz.comments
comdefz.append(rdz.comments)
datelis.append(rdz.title)
datelis.append(rdz.url)
datelis.append(rdz.author)
comdict = {'comtxt':rdz.comments}
rgdef.update({rdz.author: rdz.url})
pandic = DataFrame(rdz.json_dict)
decict.update({'url':rdz.url})
decict.update({'title':rdz.title})
decict.update({'ups': rdz.ups})
decict.update({'downs': rdz.downs})
# <codecell>
decict
# <codecell>
pandic
# <codecell>
comdict
# <codecell>
comply = []
# <codecell>
fddict = dict()
# <codecell>
fdz.body
# <codecell>
for comaq in comdefz:
for fdz in comaq:
print fdz
print fdz.author
print fdz.created_utc
print fdz.replies
fddict.update({'combody': fdz.body})
fddict.update({'comauthor': fdz.author})
fddict.update({'comup': fdz.ups})
fddict.update({'comdown': fdz.downs})
comply.append(fdz.replies)
decict.update({'created':fdz.created_utc})
decict.update({'author': fdz.author})
decict.update({'body':fdz.body})
decict.update({'replies':fdz.replies})
# <codecell>
decict
# <codecell>
fddict
# <codecell>
qwedict = decict.items() + fddict.items()
# <codecell>
alldixz = dict()
# <codecell>
for qwpz in qwedict:
print qwpz
alldixz.update({qwpz: 'test'})
# <codecell>
alldixz
# <codecell>
qwedict
# <codecell>
for coaz in comply:
print coaz
for coa in coaz:
print coa.body
print coa.author
# <codecell>
serz = Series(fddict)
# <codecell>
fddict
# <codecell>
fddict.keys()
# <codecell>
def extractlinks(html):
soup = BeautifulSoup(html)
anchors = soup.findAll('a')
links = []
for a in anchors:
links.append(a['href'])
return links
# <codecell>
cydict = fddict.values()
# <codecell>
for itz in cydict:
print itz
# <codecell>
chedict = {'blah': 'testing'}
# <codecell>
#fixurl = BeautifulSoup(fddict.values())
# <codecell>
for coma in comdefz:
#print coma
#chedict.update({'first': coma})
for co in coma:
print co
chedict.update({co.author: co.body})
# <codecell>
getsdrdir = ('/home/wcmckee/getsdrawndotcom/')
# <codecell>
os.listdir(getsdrdir)
# <codecell>
chedict
# <codecell>
#jsdum = json.loads(chedict)
# <codecell>
rcoms = chedict.keys()
rvals = chedict.values()
imcom = []
# <codecell>
for rvs in rvals:
print rvs
if '.jpg' or '.png' in rvs:
imcom.append(rvs)
# <codecell>
imcom
# <codecell>
#fuldoc = doc.render()
# <codecell>
# <codecell>
doc = dominate.document(title='Dominate your HTML')
with doc.head:
link(rel='stylesheet', href='style.css')
script(type='text/javascript', src='script.js')
with doc:
with div(id='header').add(ol()):
for imz in imcom:
#print imz
p(imz)
#with div():
# attr(cls='body')
# p('Lorem ipsum..')
#print doc
# <codecell>
for docin in doc.head.children:
print docin
# <codecell>
for pain in docin.parent.children:
print pain
# <codecell>
doc.body.parent.children
# <codecell>
# <codecell>
#soup = BeautifulSoup(doc)
#print(soup.prettify())
# <codecell>
#extractlinks()
# <codecell>
#for imc in imcom:
# print imc
# <codecell>
#doc.body
# <codecell>
# <codecell>
#doc.render()
# <codecell>
#for dicaz in doc.children:
# print dicaz
# <codecell>
# <codecell>
#for imz in imcom:
# print imz
# <codecell>
#for rez in rcoms:
# print rez
# <codecell>
# <codecell>
#for rgt in rgdef.values():
# if '.jpg' in rgt:
# print rgt
# <codecell>
import dominate
from dominate.tags import *
doc = dominate.document(title='RedditGetsDrawn Recent Reference')
with doc.head:
link(rel='stylesheet', href='style.css')
script(type='text/javascript', src='script.js')
with div():
attr(cls='header')
h1('RedditGetsDrawn Recent Reference')
p('updated ', strftime("%a, %d %b %Y %H:%M:%S +0000", gmtime()))
with doc:
with div(id='body').add(ol()):
for rdz in rdnew:
h1(rdz.title)
a(rdz.url)
if '.jpg' or '.png' in rdz.url:
print rdz.url
p(img(rdz.url, src='%s' % rdz.url))
#print rdz.url
#if '.jpg' in rdz.url:
# img(rdz.urlz)
#else:
# a(rdz.urlz)
p(str(rdz.author))
#li(img(i.lower(), src='%s' % i))
with div():
attr(cls='body')
p('RGDRecentReference is open source')
a('http://github.com/wcmckee/wcmckee')
#print doc
# <codecell>
rgdir = ('/home/wcmckee/rgdrecentReference/')
# <codecell>
doc.render()
# <codecell>
os.chdir(rgdir)
# <codecell>
mkindex = open('index.html', 'w')
mkindex.write(str(doc))
mkindex.close()
# <codecell>
#print str(doc)
# <codecell>
print strftime("%a, %d %b %Y %H:%M:%S +0000")
# <codecell>
savedate = strftime("%d" + "-" + "%m" + "-" + "%Y" + "-" + "%H")
# <codecell>
def timeret():
return strftime("%d" + "-" + "%m" + "-" + "%Y" + "-" + "%H")
def givmd():
return str(savedate + '.md')
def givdic():
return rgdir.replace('/', '-')
# <codecell>
givdic()
# <rawcell>
# timeret()
# <codecell>
givmd()
# <codecell>
savedate
# <codecell>
deepone = str(savedate + '.md')
# <codecell>
deepone
# <codecell>
#os.chdir('/home/wcmckee/brobeur-blog-post/')
# <codecell>
#brobeind = open('índex.html', 'r')
# <codecell>
#brotest = open('índex.html', 'r')
#brotest.read()
# <codecell>
redposts = ('/home/wcmckee/rgdrecentReference/posts/pandas')
# <codecell>
os.chdir(redposts)
# <codecell>
time.asctime()
# <codecell>
savinx = open(str(deepone), 'w')
# <codecell>
savinx.write(str(rgdef))
# <codecell>
savinx.close()
# <codecell>
deepone
# <codecell>
decict
# <codecell>
decict.update({'datehour': givmd()})
# <codecell>
depan = Series(decict)
# <codecell>
fepan = Series(fddict)
# <codecell>
mepan = (fepan)+(depan)
# <codecell>
depan
# <codecell>
feram = pd.DataFrame(fepan)
# <codecell>
fepan
# <codecell>
feram
# <codecell>
mepan
# <codecell>
defed = DataFrame(depan)
# <codecell>
#defed.append(fepan)
# <codecell>
depan
# <codecell>
fepan
# <codecell>
mergz = depan.append(fepan)
# <codecell>
mergz
# <codecell>
# <codecell>
defed
# <codecell>
defhtml = defed.to_html()
# <codecell>
wrhtm = open('index.html', 'w')
wrhtm.write(defhtml)
wrhtm.close()
# <codecell>
# <codecell>
# <codecell>