Last active
December 5, 2021 00:12
-
-
Save ninjamar/bf76adcca78e66153068a155766c4a97 to your computer and use it in GitHub Desktop.
Scratch User Status
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| import requests | |
| user = 'ninjamar' | |
| r = requests.get(f'https://scratch.mit.edu/users/{user}') | |
| c = ''.join([i.decode().strip() for i in r.iter_lines()]) | |
| iscratcher = re.compile("<span class=\"group\">Scratcher</span>") | |
| isscratchteam = re.compile("<span class=\"group\">Scratch Team</span>") | |
| isnewscratcher = re.compile("<span class=\"group\">New Scratcher</span>") | |
| if iscratcher.search(c): | |
| print(f'{user} is a scratcher') | |
| elif isscratchteam.search(c): | |
| print(f'{user} is on the scratch team') | |
| elif isnewscratcher.search(c): | |
| print(f'{user} is a new scratcher') |
Author
ok. i think it might be isscratcher.test
import fetch from "node-fetch";
console.log("starting");
(async () => {
const user = "god286";
const r = await fetch(`https://scratch.mit.edu/users/${user}`, {
headers: {
"User-Agent": "Mozilla 5.0",
},
});
console.log(r.ok)
const c = await r.text();
let split = c.split("/n");
for (let index = 0; index < split.length; index++) {
split[index] = split[index].trim();
}
const isScratcher = new RegExp('<span class="group">Scratcher</span>');
const isScratchTeam = new RegExp('<span class="group">Scratch Team</span>');
const isNew = new RegExp('<span class="group">New Scratcher</span>');
isScratcher.test(split);
if (isScratcher.test(split)) {
console.log(`${user} is a scratcher`);
} else if (isScratchTeam.test(split)) {
console.log(`${user} is on the scratch team`);
} else if (isNew.test(split)) {
console.log(`${user} is a new scratcher`);
} else {
console.log("nothing found")
}
})();gives "nothing found"..?
Author
The code doesn't seem to be replacing all occurrences of \n,\t,' ' with ``
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
TypeError: isScratcher.search is not a function
don't worry I've switched to JSDom, thanks for your help though!! python seems quite cool for stuff!