Skip to content

Instantly share code, notes, and snippets.

@turnipsoup
Last active June 8, 2019 04:09
Show Gist options
  • Save turnipsoup/fabce79a58ba4599b228ee3c681775f0 to your computer and use it in GitHub Desktop.
Save turnipsoup/fabce79a58ba4599b228ee3c681775f0 to your computer and use it in GitHub Desktop.
Gets lofi tracks from reddit and makes a list for you.
#!/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