diff options
author | Anthony Wang | 2024-09-30 00:50:54 -0400 |
---|---|---|
committer | Anthony Wang | 2024-09-30 00:51:11 -0400 |
commit | c1b1b3f017a337ab0218710a6a0db6100d9cf07a (patch) | |
tree | 4970e8f16c78c93d6f4829e3e2b64062f4f099c2 /static | |
parent | 0465392836d91a13a78ba5bf1d24cb7ea2f66e36 (diff) |
Make script try reading data from file
Diffstat (limited to 'static')
-rw-r--r-- | static/img/anime-birthdays.png | bin | 24398 -> 17549 bytes | |||
-rw-r--r-- | static/src/moegirlpedia-birthdays.py | 23 |
2 files changed, 15 insertions, 8 deletions
diff --git a/static/img/anime-birthdays.png b/static/img/anime-birthdays.png Binary files differindex b179e2e..d973bd5 100644 --- a/static/img/anime-birthdays.png +++ b/static/img/anime-birthdays.png diff --git a/static/src/moegirlpedia-birthdays.py b/static/src/moegirlpedia-birthdays.py index baa8da3..b819bdf 100644 --- a/static/src/moegirlpedia-birthdays.py +++ b/static/src/moegirlpedia-birthdays.py @@ -1,19 +1,26 @@ import re import urllib.request +import sys import numpy as np import matplotlib.pyplot as plt headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3'} -cnts = np.zeros((12, 31), dtype=np.uint8) +cnts = np.zeros((31, 12), dtype=np.uint8) -for month in range(12): - monthlen = 29 if month == 1 else 30 if month in [3, 5, 8, 10] else 31 - for day in range(monthlen): - req = urllib.request.Request(f'https://moegirl.uk/Category:{month + 1}%E6%9C%88{day + 1}%E6%97%A5', headers=headers) - body = urllib.request.urlopen(req).read().decode('utf-8') - cnts[month, day] = int(re.search(r'(\d*)个页面', body).group()[:-3]) - print(month + 1, day + 1, cnts[month, day]) +if len(sys.argv) > 1: + with open(sys.argv[1]) as f: + for l in f.readlines(): + x = list(map(int, l.split())) + cnts[x[1] - 1, x[0] - 1] = x[2] +else: + for month in range(12): + monthlen = 29 if month == 1 else 30 if month in [3, 5, 8, 10] else 31 + for day in range(monthlen): + req = urllib.request.Request(f'https://moegirl.uk/Category:{month + 1}%E6%9C%88{day + 1}%E6%97%A5', headers=headers) + body = urllib.request.urlopen(req).read().decode('utf-8') + cnts[day, month] = int(re.search(r'(\d*)个页面', body).group()[:-3]) + print(month + 1, day + 1, cnts[day, month]) plt.matshow(cnts) plt.colorbar() |