small updates & fixes

This commit is contained in:
Peter Molnar 2023-06-01 18:06:30 +01:00
parent 7cd5ba9364
commit edc40423e8
6 changed files with 57 additions and 13 deletions

View file

@ -133,7 +133,7 @@ class DAFav(common.ImgFav):
"deviantart_%s_%s_%s" "deviantart_%s_%s_%s"
% ( % (
common.url2slug("%s" % self.deviation.author), common.url2slug("%s" % self.deviation.author),
self.id, self.id.replace("-", "_"),
common.url2slug("%s" % self.title), common.url2slug("%s" % self.title),
), ),
) )

View file

@ -6,11 +6,13 @@ from operator import attrgetter
from collections import namedtuple from collections import namedtuple
import requests import requests
import arrow import arrow
from datetime import datetime
import settings import settings
import keys import keys
from pprint import pprint from pprint import pprint
from math import floor from math import floor
from common import cached_property from common import cached_property
import sys
Track = namedtuple( Track = namedtuple(
"Track", ["timestamp", "artist", "album", "title", "artistid", "albumid", "img"] "Track", ["timestamp", "artist", "album", "title", "artistid", "albumid", "img"]
@ -43,9 +45,10 @@ class LastFM(object):
r = csv.reader(f) r = csv.reader(f)
for row in r: for row in r:
try: try:
timestamps.append(arrow.get(row[0]).timestamp)
timestamps.append(int(datetime.fromisoformat(row[0]).timestamp()))
except Exception as e: except Exception as e:
logging.error("arrow failed on row %s", row) logging.error("arrow failed on row %s as: %s", row[0], e)
continue continue
return timestamps return timestamps
@ -64,7 +67,7 @@ class LastFM(object):
if ts.timestamp in self.existing: if ts.timestamp in self.existing:
continue continue
entry = Track( entry = Track(
ts.format("YYYY-MM-DDTHH:mm:ssZ"), ts.format("YYYY-MM-DDTHH:mm:ssZZ"),
track.get("artist").get("#text", ""), track.get("artist").get("#text", ""),
track.get("album").get("#text", ""), track.get("album").get("#text", ""),
track.get("name", ""), track.get("name", ""),

View file

@ -8,7 +8,6 @@ import subprocess
import json import json
from io import BytesIO from io import BytesIO
import lxml.etree as etree import lxml.etree as etree
from slugify import slugify
import requests import requests
from requests.auth import HTTPBasicAuth from requests.auth import HTTPBasicAuth
import arrow import arrow
@ -18,6 +17,49 @@ import yaml
from pprint import pprint from pprint import pprint
import feedparser import feedparser
# https://www.peterbe.com/plog/fastest-python-function-to-slugify-a-string
NON_URL_SAFE = [
'"',
"#",
"$",
"%",
"&",
"+",
",",
"/",
":",
";",
"=",
"?",
"@",
"[",
"]",
"^",
"`",
"{",
"|",
"}",
"~",
"'",
".",
"\\",
]
# TRANSLATE_TABLE = {ord(char): "" for char in NON_URL_SAFE}
RE_NON_URL_SAFE = re.compile(
r"[{}]".format("".join(re.escape(x) for x in NON_URL_SAFE))
)
RE_REMOVESCHEME = re.compile(r"^https?://(?:www)?")
def slugify(text):
text = RE_REMOVESCHEME.sub("", text).strip()
text = RE_NON_URL_SAFE.sub("", text).strip()
text = text.lower()
text = "_".join(re.split(r"\s+", text))
return text
TMPFEXT = ".xyz" TMPFEXT = ".xyz"
MDFEXT = ".md" MDFEXT = ".md"
@ -42,9 +84,9 @@ def utfyamldump(data):
def url2slug(url): def url2slug(url):
return slugify( return slugify(
re.sub(r"^https?://(?:www)?", "", url), re.sub(r"^https?://(?:www)?", "", url)
only_ascii=True, #only_ascii=True,
lower=True, #lower=True,
)[:200] )[:200]

3
run
View file

@ -1,6 +1,5 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -euo pipefail source .venv/bin/activate
IFS=$'\n\t'
python3 run.py python3 run.py

4
run.py
View file

@ -9,11 +9,11 @@ import HackerNews
from pprint import pprint from pprint import pprint
silos = [ silos = [
DeviantArt.DAFavs(),
Flickr.FlickrFavs(), Flickr.FlickrFavs(),
Tumblr.TumblrFavs(), Tumblr.TumblrFavs(),
DeviantArt.DAFavs(),
# Artstation.ASFavs(), # Artstation.ASFavs(),
LastFM.LastFM(), # LastFM.LastFM(),
HackerNews.HackerNews() HackerNews.HackerNews()
] ]

View file

@ -9,7 +9,7 @@ class nameddict(dict):
__delattr__ = dict.__delitem__ __delattr__ = dict.__delitem__
paths = nameddict({ paths = nameddict({
"archive": os.path.join(os.path.expanduser('~'), "archive"), "archive": os.path.join(os.path.expanduser('~'), "archiv"),
}) })
loglevels = {"critical": 50, "error": 40, "warning": 30, "info": 20, "debug": 10} loglevels = {"critical": 50, "error": 40, "warning": 30, "info": 20, "debug": 10}