Skip to content

Instantly share code, notes, and snippets.

@TiloGit
Last active November 16, 2021 06:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save TiloGit/51367aca5a4df726a7061288d8430828 to your computer and use it in GitHub Desktop.
Save TiloGit/51367aca5a4df726a7061288d8430828 to your computer and use it in GitHub Desktop.
Duolingo via Phyton
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)
@TiloGit
Copy link
Author

TiloGit commented Sep 1, 2020

@TiloGit
Copy link
Author

TiloGit commented Sep 2, 2020

remember to change duolingo.py;

#import requests
from botocore.vendored import requests
#from werkzeug.datastructures import MultiDict

here the AWS YAML for the function

AWSTemplateFormatVersion: '2010-09-09'
Transform: 'AWS::Serverless-2016-10-31'
Description: An AWS Serverless Specification template describing your function.
Resources:
  duo2:
    Type: 'AWS::Serverless::Function'
    Properties:
      Handler: main_AWS.main
      Runtime: python3.7
      CodeUri: .
      Description: ''
      MemorySize: 128
      Timeout: 15
      Role: 'arn:aws:iam::753189718521:role/service-role/duolingoRole'
      Events:
        Schedule1:
          Type: Schedule
          Properties:
            Schedule: cron(0 */8 * * ? *)
      Environment:
        Variables:
          passwords: Your__PW
          usernames: Your__ID

@TiloGit
Copy link
Author

TiloGit commented Nov 16, 2021

to avoid issues with aws from botocore.vendored import requests add requirements.txt which include "request', export lambda function and
local download with pip install -r requirements.txt -t . zip up and upload to AWS lambda.

that works with python 3.9 it seems.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment