Last active
June 8, 2019 04:09
-
-
Save turnipsoup/fabce79a58ba4599b228ee3c681775f0 to your computer and use it in GitHub Desktop.
Gets lofi tracks from reddit and makes a list for you.
This file contains 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
#!/usr/bin/env python3 | |
# | |
import requests | |
import json | |
import subprocess | |
import datetime | |
currdate = datetime.datetime.now() | |
playlistURLbase = "https://www.youtube.com/watch_videos?video_ids=" | |
headers = { | |
"User-Agent": "lofi" | |
} | |
r = requests.get("https://www.reddit.com/r/lofi.json?limit=100", headers=headers) | |
json_data = json.loads(r.content) | |
list_urls = [] | |
for item in json_data["data"]["children"]: | |
if "feature=" in item['data']['url']: | |
pass | |
elif "youtu.be" in item["data"]["url"]: | |
list_urls.append(item["data"]["url"].split("/")[-1]) | |
elif "youtube.com/watch" in item["data"]["url"]: | |
list_urls.append(item["data"]["url"].split("?v=")[-1].split("&")[0]) | |
currfile = [] | |
currfilelength = 0 | |
with open("/var/www/html_per/lofi_playlist", "r") as fi: | |
currfile = fi.readlines()[1:] | |
currfilelength = len(fi.readlines()) | |
fi.close() | |
if currfilelength >= 4: | |
with open("/var/www/html_per/lofi_playlist", "w") as fi: | |
fi.write(currfile) | |
fi.close() | |
with open ('/var/www/html_per/lofi_playlist', "a") as f: | |
f.write("<a href='" + playlistURLbase + ",".join(list_urls) + "'>" + str(currdate) + "</a>" + "\n") | |
f.close() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment