KartikTalwar / Duolingo

Unofficial Duolingo API Written in Python
MIT License
822 stars 129 forks source link

how to - mini script: auto buy streak freeze #54

Open TiloGit opened 6 years ago

TiloGit commented 6 years ago

here mini script to check few times a day (see crontab schedule) and try to buy streak freeze. For your off-line vacation :-)

Not tried for multiply languages (if you learn more than one) was a quick hack, please feel free to adapt or add to wiki here. I run it on my Pi which has kodi via osmc installed.

#######Start of script
##redir in cron job 
## 0 2,8,14,20 * * * python /home/osmc/MyScript/DuolingoVacation.py >> /home/osmc/MyScript/log/DuoVac_$(date +\%Y\%m\%d).log

import logging
import sys
import duolingo

ScriptName = 'Duolingo Vacation'
USER='MyUserName here'

logging.basicConfig(format='%(asctime)s %(levelname)s %(message)s',level=logging.INFO,stream=sys.stdout)
logging.info('=========Start Script: ' + (ScriptName))

#######Login/pick user. 
#lingo = duolingo.Duolingo(USER)
lingo  = duolingo.Duolingo(USER, password='My password here')
logging.info('Logon as: ' + (USER))

#######Simple stuff Lang
Mylanguages = lingo.get_languages(abbreviations=False)
logging.info('Languages: ' + str(Mylanguages))

#######Simple stuff Get streak info
streak_info = lingo.get_streak_info()
logging.info('streak_info: ' + str(streak_info))

#######Buy Freeze
BuyStreak = lingo.buy_streak_freeze()
logging.info('streak_buy: ' + str(BuyStreak))

logging.info('=========End Script: ' + (ScriptName))

Example log output of the above code.

2018-03-05 02:00:01,832 INFO =========Start Script: Duolingo Vacation
2018-03-05 02:00:07,391 INFO Logon as: MyUserName here
2018-03-05 02:00:07,392 INFO Languages: [u'Spanish']
2018-03-05 02:00:07,398 INFO streak_info: {'site_streak': 733, 'daily_goal': 50, 'streak_extended_today': False}
2018-03-05 02:00:07,717 INFO streak_buy: True
2018-03-05 02:00:07,718 INFO =========End Script: Duolingo Vacation
2018-03-05 08:00:02,253 INFO =========Start Script: Duolingo Vacation
2018-03-05 08:00:05,936 INFO Logon as: MyUserName here
2018-03-05 08:00:05,937 INFO Languages: [u'Spanish']
2018-03-05 08:00:05,937 INFO streak_info: {'site_streak': 733, 'daily_goal': 50, 'streak_extended_today': False}
2018-03-05 08:00:06,062 INFO streak_buy: False
2018-03-05 08:00:06,062 INFO =========End Script: Duolingo Vacation
2018-03-05 14:00:02,104 INFO =========Start Script: Duolingo Vacation
2018-03-05 14:00:05,832 INFO Logon as: MyUserName here
2018-03-05 14:00:05,833 INFO Languages: [u'Spanish']
2018-03-05 14:00:05,834 INFO streak_info: {'site_streak': 734, 'daily_goal': 50, 'streak_extended_today': True}
2018-03-05 14:00:05,954 INFO streak_buy: False
2018-03-05 14:00:05,954 INFO =========End Script: Duolingo Vacation
2018-03-05 20:00:01,981 INFO =========Start Script: Duolingo Vacation
2018-03-05 20:00:05,312 INFO Logon as: MyUserName here
2018-03-05 20:00:05,313 INFO Languages: [u'Spanish']
2018-03-05 20:00:05,313 INFO streak_info: {'site_streak': 734, 'daily_goal': 50, 'streak_extended_today': True}
2018-03-05 20:00:05,437 INFO streak_buy: False
2018-03-05 20:00:05,437 INFO =========End Script: Duolingo Vacation
ingochris commented 6 years ago

Good idea, @TiloGit!

ksgubanov commented 6 years ago

Nice! I was about doing a similar thing.

alexsanjoseph commented 5 years ago

https://github.com/alexsanjoseph/duolingo-save-streak - This will help you set it up on AWS lambda (it's free for such a small load) so that it will work even if your PC gets switched off.

TiloGit commented 5 years ago

https://github.com/alexsanjoseph/duolingo-save-streak - This will help you set it up on AWS lambda (it's free for such a small load) so that it will work even if your PC gets switched off.

added some how to info, but you might want to sanitize this as author: https://github.com/alexsanjoseph/duolingo-save-streak/issues/1