diff options
Diffstat (limited to 'scripts/fill.image_urls.py')
| -rwxr-xr-x | scripts/fill.image_urls.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/scripts/fill.image_urls.py b/scripts/fill.image_urls.py index b7e0f2e..d3a10de 100755 --- a/scripts/fill.image_urls.py +++ b/scripts/fill.image_urls.py @@ -5,7 +5,7 @@ import sys import postgresql from urllib.parse import urlparse -db = postgresql.open("pq://postgres:root@localhost/dumpfm") +db = postgresql.open("pq://postgres:root@localhost/humpfm") db.execute("SET CLIENT_ENCODING to 'UNICODE'") def get_num_images_in_db(): @@ -58,15 +58,23 @@ def get_urls_from_messages(messages): return urls # this does 3 things... -# convert 'http://dumpfm.s3.amazonaws.com' to '/' +# convert archive URLs to a shorter local form # drops 'http://' from urls -# drops 'dump.fm/images' from urls +# drops 'hump.fm/images' from urls # the client is expected to rebuild urls based on this heuristic: # if the url starts with '/', prepend '/' # otherwise, prepend 'http://' def make_url_smaller(url): - if url[:37] == 'http://dumpfm.s3.amazonaws.com/images': - url = '/images' + url[37:] + prefixes = [ + 'https://archive.hump.fm/images', + 'http://archive.hump.fm/images', + 'https://s3.amazonaws.com/archive.hump.fm/images', + 'http://s3.amazonaws.com/archive.hump.fm/images', + ] + for prefix in prefixes: + if url[:len(prefix)] == prefix: + url = '/images' + url[len(prefix):] + break if url[:21] == '/images': url = url[21:] else: |
