Last active
November 16, 2021 06:50
-
-
Save TiloGit/51367aca5a4df726a7061288d8430828 to your computer and use it in GitHub Desktop.
Duolingo via Phyton
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
def item_already_equipped(lingo, item): | |
if item == 'streak_freeze': | |
return lingo.__dict__['user_data'].__dict__['tracking_properties']['num_item_streak_freeze'] > 0 | |
if item == 'rupee_wager': | |
return lingo.__dict__['user_data'].__dict__['tracking_properties']['has_item_rupee_wager'] | |
def main(a, b): | |
import duolingo, os | |
username = os.environ['usernames'] | |
password = os.environ['passwords'] | |
print("Test__Tilo__Here") | |
print("environment variable: " + os.environ['usernames']) | |
print("loaded one: " + username) | |
try: | |
lingo = duolingo.Duolingo(username, password) | |
except ValueError: | |
raise Exception("Username Invalid") | |
#here the test/report stuff | |
print("---InfoPart---Start---") | |
Mylanguages = lingo.get_languages() | |
print(username + " get_languages for " + str(Mylanguages)) | |
streak_info = lingo.get_streak_info() | |
print(username +" get_streak_info for " + str(streak_info)) | |
MyInfo = lingo.get_user_info() | |
print(username +" Info ID: " + str(MyInfo["id"])) | |
print(username +" Info fullname: " + str(MyInfo["fullname"])) | |
print(username +" Info location: " + str(MyInfo["location"])) | |
print(username +" Info contribution_points: " + str(MyInfo["contribution_points"])) | |
print(username +" Info created: " + str.strip(MyInfo["created"])) | |
print(username +" Info learning_language_string: " + str(MyInfo["learning_language_string"])) | |
print(username +" streak_freeze: " + str(lingo.__dict__['user_data'].__dict__['tracking_properties']['num_item_streak_freeze'])) | |
print(username +" rupee_wager: " + str(lingo.__dict__['user_data'].__dict__['tracking_properties']['has_item_rupee_wager'])) | |
user_data_resp = lingo.get_data_by_user_id() | |
print(username +" Info lingots: " + str(user_data_resp['lingots'])) | |
print(username +" Info totalXp: " + str(user_data_resp['totalXp'])) | |
print(username +" Info monthlyXp: " + str(user_data_resp['monthlyXp'])) | |
print(username +" Info weeklyXp: " + str(user_data_resp['weeklyXp'])) | |
print(username +" Info gems: " + str(user_data_resp['gems'])) | |
print(username +" Info currentCourse.crowns: " + str(user_data_resp['currentCourse']['crowns'])) | |
print("---InfoPart---End---") | |
#new buy stuff 2020-08-31 | |
stuff_to_purchase = ['streak_freeze', 'rupee_wager'] | |
for item in stuff_to_purchase: | |
if(item_already_equipped(lingo, item)): | |
print("Item "+ item + " already equipped! Skipping...") | |
continue | |
try: | |
print("Trying to Buy " + item + " for " + username) | |
lingo.buy_item(item, 'es') | |
print("Bought " + item + " for " + username) | |
except duolingo.AlreadyHaveStoreItemException: # no longer triggered AFAIK | |
print("Item Already Equipped") | |
except Exception: | |
raise ValueError("Unable to buy " + item) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
to avoid issues with aws
from botocore.vendored import requests
add requirements.txt which include "request', export lambda function andlocal download with
pip install -r requirements.txt -t .
zip up and upload to AWS lambda.that works with python 3.9 it seems.