Skip to content

Instantly share code, notes, and snippets.

@cymruu
Created May 27, 2017 10:10
Show Gist options
  • Save cymruu/dd3386e3699f43a15c043311b1489836 to your computer and use it in GitHub Desktop.
Save cymruu/dd3386e3699f43a15c043311b1489836 to your computer and use it in GitHub Desktop.
import wykop
import config
import sys
import math
from datetime import datetime
import queue
from threading import Thread
from threading import Timer
q = queue.Queue()
entries = []
API = wykop.WykopAPI(config.application['apikey'], config.application['secret'], output='clear')
API.authenticate(config.user['login'], config.user['connectionKey'])
username = str(sys.argv[1])
user = API.request('profile', 'index', [username])
pages = math.ceil(user['entries']/25)
threads = math.floor(pages/5)
if(threads>12):
threads=12
if(threads==0):
threads=1
threads = 6
plusy = 0
print('Pobieram: ',pages, ' stron uzywajac ', threads, ' watkow')
for i in range(1, pages+1):
q.put(i)
def getPage(entries):
while not q.empty():
page = q.get()
print('pobieram stronę: '+str(page))
pageX = API.request('profile', 'entries', [username], {'page': page})
if(len(pageX)):
entries+=pageX
q.task_done()
startTime = datetime.now()
for i in range(threads):
t1 = Thread(target = getPage, args=[entries])
t1.start()
q.join()
endTime = datetime.now()
entries = sorted(entries, key=lambda x:x['vote_count'], reverse=True)
for entry in entries:
plusy+=entry['vote_count']
eString = ''
for e in range(10):
eString += '['+str(entries[e]['id'])+'](http://wykop.pl/wpis/' + str(entries[e]['id']) + ')' + ' - ' + str(entries[e]['vote_count']) + '\n'
body = '#najlepszewpisy\nNajlepsze wpisy uzytkownika @{}\n{}\nPodsumowanie\nwpisow: {}, plusow: {} plusow/wpis: {}\nCzas pobierania wpisow ({} stron / {} wątkow): {}'.format(username, eString, len(entries), plusy, plusy/len(entries), pages, threads, endTime-startTime)
print(body)
API.request('entries', 'addcomment', [20262543], post_params = {'body': body})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment