Tumblr backup updated for Python 3#96
Conversation
|
|
||
| def pages_per_month(y, m): | ||
| posts = len(self.index[y][m]) | ||
| return posts / posts_page + bool(posts % posts_page) |
There was a problem hiding this comment.
| return posts / posts_page + bool(posts % posts_page) | |
| return posts // posts_page + bool(posts % posts_page) |
use floor division for an integer result
| def save_year(self, idx, year): | ||
| idx.write('<h3>%s</h3>\n<ul>\n' % year) | ||
| for month in sorted(list(self.index[year].keys()), reverse=options.reverse_index): | ||
| tm = time.localtime(time.mktime(time.struct_time([year, month, 3, 0, 0, 0, 0, 0, -1]))) |
There was a problem hiding this comment.
for time.struct_time([year, month, 3, 0, 0, 0, 0, 0, -1]), we can simply use a tuple (year, month, 3, 0, 0, 0, 0, 0, -1)
| See https://groups.google.com/d/msg/tumblr-api/f-rRH6gOb6w/sAXZIeYx5AUJ""" | ||
| try: | ||
| resp = urlopen('http://%s/' % blog_name) | ||
| page_data = resp.read() |
There was a problem hiding this comment.
| page_data = resp.read() | |
| page_data = resp.read().decode("utf-8") |
can restore lines 559-561 by committing this change
|
|
||
| # ensure the right date/time format | ||
| try: | ||
| locale.setlocale(locale.LC_TIME, '') |
There was a problem hiding this comment.
| locale.setlocale(locale.LC_TIME, '') | |
| locale.setlocale(locale.LC_TIME, '') | |
| locale.setlocale(locale.LC_CTYPE, '') |
also need to set locale.LC_CTYPE
|
Thanks! Is it possible to have a single script that works with both Python 2 and Python 3? Otherwise, the installation and setup gets too complicated for the average user. |
|
Python2 is depreciated, and so the average user should only be using Python3 anyway. |
|
I have a problem running this version (I am using 3.5 with the Mac OS X command line) python tumblr_backup_python3.py -O /Volumes/G-DRIVE\ ev/Tumblr blogname |
| if len(options.period) == 8: | ||
| i = 2 | ||
| tm[2] = int(options.period[6:8]) | ||
| options.p_start = time.mktime(tm) |
There was a problem hiding this comment.
| options.p_start = time.mktime(tm) | |
| options.p_start = time.mktime(tuple(tm)) |
a tuple or time.struct_time object is required
| tm[2] = int(options.period[6:8]) | ||
| options.p_start = time.mktime(tm) | ||
| tm[i] += 1 | ||
| options.p_stop = time.mktime(tm) |
There was a problem hiding this comment.
| options.p_stop = time.mktime(tm) | |
| options.p_stop = time.mktime(tuple(tm)) |
| for _ in range(10): | ||
| try: | ||
| resp = urllib.request.urlopen(url) | ||
| data = resp.read() |
There was a problem hiding this comment.
| data = resp.read() | |
| data = resp.read().decode("utf-8") |
for compatibility with python version <3.6
That's premature. macOS High Sierra only comes with Python 2, e.g. |
|
@bbolli My local fork of tumblr-utils (with features from a lot of my PRs) is fully compatible with both Python 2 and Python 3 in a single script. So, it's possible, it just requires a little more care. |
|
You might want to remove that API key |
Use this version for Python 3. It was converted first by hand and then I also ran 2to3 on it just to be safe. It has been tested for both full and incremental backup which was successful.