Last active
August 29, 2015 14:16
-
-
Save hejmsdz/8b8852d570775f6bac33 to your computer and use it in GitHub Desktop.
Lingot giveaway
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 json | |
import re | |
import pyduo | |
give = 15 | |
mock = False | |
duo = pyduo.Duolingo() | |
duo.login("username", "password") | |
# I haven't created classes to represent the forum. The line below should look like: | |
# thread = duo.get_discussion(7411529) | |
# returning a pyduo.discussion.Discussion object in the future. | |
# the Discussion object would have comments attribute (a list of pyduo.discussion.Comment instances) | |
# and there would be a love() method for each of them, etc. | |
# You get the point? | |
thread = duo.s.get(duo.url("comments/7411529")).json() | |
for comment in thread['comments']: | |
cid = comment['id'] | |
amount = give-(comment['love'] or 0) | |
if amount <= 0: | |
continue | |
print "{} lingots for comment {}:".format(amount, cid), | |
if not mock: | |
for i in range(amount): | |
duo.s.post(duo.url("comments/{}/love".format(cid))) | |
print ".", | |
# update the post with current number of my lingots | |
lingots = duo.get_user().lingots | |
thread['message'] = re.sub("\*\*(.+)\*\*", "**{}**".format(lingots), thread['message']) | |
duo.s.put(duo.url("comments/7411529"), data=json.dumps(thread), headers={'Content-type': 'application/json'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment