Download pool/shard009/Python/0080414_lastfm.py from Variable-role/sajaniemi_variable_dataset_large: direct link, hf CLI and curl.
- Browser
- Download file 1.85 kB
-
https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard009/Python/0080414_lastfm.py
- Command line
-
hf download hf://datasets/Variable-role/sajaniemi_variable_dataset_large/pool/shard009/Python/0080414_lastfm.py
-
curl -L -o 0080414_lastfm.py https://huggingface.co/datasets/Variable-role/sajaniemi_variable_dataset_large/resolve/main/pool/shard009/Python/0080414_lastfm.py
1.85 kB
| import re | |
| import requests | |
| import json as J | |
| from module import * | |
| lastfmdict = "modules/rsrc/lastfm.dict" | |
| users = {} | |
| def loaddict(): | |
| global users | |
| try: | |
| with open(lastfmdict, 'r') as f: | |
| users = J.load(f) | |
| pass | |
| pass | |
| except: | |
| print "failed to load lastfm.dict; corruption possible!" | |
| pass | |
| return | |
| def writedb(): | |
| global users | |
| with open(lastfmdict, 'w') as f: | |
| J.dump(users, f) | |
| pass | |
| return | |
| # TODO(frozen) Handle escapes of the form %dd | |
| def unhtml(m): | |
| m = m.replace("+noredirect/", "") | |
| m = m.replace("+", " ") | |
| m = m.replace(""", "\"") | |
| m = m.replace("&", "&") | |
| m = m.replace("%26", "&") | |
| m = m.replace("/_/", " - ") | |
| return m | |
| def cmdmsg(senderf, channame, speaker, cmdstr, isact): | |
| global users | |
| cmdstr = cmdstr.strip() | |
| cmd = cmdstr.split(" ", 2) | |
| if cmd[0] in ["fm", "np"]: | |
| if len(cmd) == 3 and cmd[1] == "set": | |
| u = cmd[2] | |
| users[speaker[0]] = u | |
| writedb() | |
| pass | |
| elif len(cmd) == 2: | |
| u = cmd[1] | |
| pass | |
| else: | |
| try: | |
| u = users[speaker[0]] | |
| pass | |
| except: | |
| senderf("Uage: `!fm [username]`. " | |
| "Set default username with `!fm set username`.") | |
| return True | |
| pass | |
| response = requests.get("https://www.last.fm/user/" + u).text | |
| response = response[response.index("Recent") + len("Recent"):] | |
| m = re.search("(?<=/music/)([^/\n]*)/[^/\n]*/([^/\n]*?)(?=\")", | |
| response) | |
| senderf(speaker[0] + ": " + | |
| unhtml(m.group(1)) + " - " + unhtml(m.group(2))) | |
| return True | |
| return False | |
| def unload(): | |
| writedb() | |
| return | |
| ###### | |
| loaddict() | |