-
-
Save cymruu/bf4d84f24a05e2479e3c03768cbe4331 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
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