Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1"""LICENSE 

2Copyright 2019 Hermann Krumrey <hermann@krumreyh.com> 

3 

4This file is part of otaku-info-bot. 

5 

6otaku-info-bot is free software: you can redistribute it and/or modify 

7it under the terms of the GNU General Public License as published by 

8the Free Software Foundation, either version 3 of the License, or 

9(at your option) any later version. 

10 

11otaku-info-bot is distributed in the hope that it will be useful, 

12but WITHOUT ANY WARRANTY; without even the implied warranty of 

13MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 

14GNU General Public License for more details. 

15 

16You should have received a copy of the GNU General Public License 

17along with otaku-info-bot. If not, see <http://www.gnu.org/licenses/>. 

18LICENSE""" 

19 

20import json 

21import requests 

22from typing import Dict 

23 

24 

25def load_newest_episodes() -> Dict[int, int]: 

26 """ 

27 Loads the newest episode numbers on /r/anime's /u/autolovepon's page 

28 :return: The show's anilist ID mapped to the latest episode number 

29 """ 

30 url = "https://old.reddit.com/user/AutoLovepon.json" 

31 headers = {"User-Agent": "Mozilla/5.0"} 

32 response = requests.get(url, headers=headers) 

33 data = json.loads(response.text) 

34 

35 latest = {} # type: Dict[int, int] 

36 entries = data["data"]["children"] 

37 

38 for entry in entries: 

39 try: 

40 title = entry["data"]["title"].lower() 

41 name = title.split(" - episode ")[0].lower() 

42 episode = title.split(" - episode ")[1].split(" discussion")[0] 

43 

44 text = entry["data"]["selftext"].lower() 

45 

46 anilist_id = text\ 

47 .split("https://anilist.co/anime/")[1]\ 

48 .split(")")[0]\ 

49 .split("/")[0] 

50 anilist_id = int(anilist_id) 

51 

52 latest[anilist_id] = max(latest.get(name, 0), int(episode)) 

53 

54 except IndexError: 

55 pass 

56 

57 return latest