aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBryan Newbold <bnewbold@archive.org>2020-04-24 12:43:48 -0700
committerBryan Newbold <bnewbold@archive.org>2020-04-24 12:43:48 -0700
commite969500d6396545a1e39e554306023c95f856717 (patch)
treef548b681e1bb376b516f2441c620219d6cdec8c7
parent1f0b8be3756cc52f3c911735dbc15f4063e133d2 (diff)
downloadels-instawiki-e969500d6396545a1e39e554306023c95f856717.tar.gz
els-instawiki-e969500d6396545a1e39e554306023c95f856717.zip
updates
-rw-r--r--README.md26
-rwxr-xr-xreupload.py74
-rwxr-xr-xupdate.sh6
3 files changed, 70 insertions, 36 deletions
diff --git a/README.md b/README.md
index 7ba167d..537e056 100644
--- a/README.md
+++ b/README.md
@@ -2,6 +2,32 @@
Want to download all ELS instagram photos, with at least date metadata, then
re-upload to wiki.mako.cc (or some other location).
+## Setup
+
+You will need bot credentials for `wiki.mako.cc`; you can get these from a
+special "bot password" page. The bot needs to be able to create images and
+pages. Copy `./example.env` to `.env` and edit the lines for username and
+password; put the bot info in, not your regular account info.
+
+Using `pipenv` to generate a python virtualenv:
+
+ pipenv shell
+ pip install instaloader requests
+
+First time you run the instaloader download, it is like:
+
+ instaloader profile --no-compress-json extraordinaryleastsquares
+
+then for updates:
+
+ instaloader --fast-update --no-compress-json extraordinaryleastsquares
+
+## Re-Upload All
+
+ pipenv run ./update.sh
+
+ ls extraordinaryleastsquares/2020-0*.json | parallel -j1 ./reupload.py {}
+
## Experimentation
Using `pipenv` to generate a python virtualenv:
diff --git a/reupload.py b/reupload.py
index 94fbbe3..5d2c0a0 100755
--- a/reupload.py
+++ b/reupload.py
@@ -97,48 +97,50 @@ def reupload_post(args):
else:
image_count = 1
- if image_count != 1:
- raise NotImplementedError()
+ session = requests.Session()
+ (login_token, csrf_token) = login(session)
- jpeg_path = base_path + ".jpg"
- date_part = base_path.split('/')[1].split('_')[0].replace('-', '')
- time_part = base_path.split('/')[1].split('_')[1].replace('-', '')[:4]
- remote_name = f"CEQD_{date_part}_{time_part}_1.jpg"
- page_text = f"""[[Category:Center for Extraordinary Quarantine Dining]]
+ for image_num in range(1,image_count+1):
+
+ if image_count == 1:
+ jpeg_path = base_path + ".jpg"
+ else:
+ jpeg_path = base_path + f"_{image_num}.jpg"
+ date_part = base_path.split('/')[1].split('_')[0].replace('-', '')
+ time_part = base_path.split('/')[1].split('_')[1].replace('-', '')[:4]
+ remote_name = f"CEQD-{date_part}-{time_part}-{image_num}.jpg"
+ page_text = f"""[[Category:Center for Extraordinary Quarantine Dining]]
== Summary ==
{caption}
Imported from ELS instagram: https://www.instagram.com/p/{shortcode}/
- """
-
- session = requests.Session()
- (login_token, csrf_token) = login(session)
-
- # First, check if file already exists
- existing = get_imageinfo(remote_name, session)
- if existing:
- print(json.dumps(existing, sort_keys=True, indent=2))
- sys.exit(-1)
-
- # If it doesn't, upload it!
- print(f"Uploading {remote_name}")
- resp = session.post(
- BASE_URL,
- data={
- "action": "upload",
- "filename": remote_name,
- "text": page_text,
- "format": "json",
- "token": csrf_token,
- "ignorewarnings": 1
- },
- files={
- 'file': ('filename.jpg', open(jpeg_path, 'rb'), 'multipart/form-data'),
- },
- )
- resp.raise_for_status()
- print(json.dumps(resp.json(), sort_keys=True, indent=2)
+ """
+
+ # First, check if file already exists
+ existing = get_imageinfo(remote_name, session)
+ if existing:
+ print(f"Already exists: {remote_name}")
+ continue
+
+ # If it doesn't, upload it!
+ print(f"Uploading: {remote_name}")
+ resp = session.post(
+ BASE_URL,
+ data={
+ "action": "upload",
+ "filename": remote_name,
+ "text": page_text,
+ "format": "json",
+ "token": csrf_token,
+ "ignorewarnings": 1
+ },
+ files={
+ 'file': ('filename.jpg', open(jpeg_path, 'rb'), 'multipart/form-data'),
+ },
+ )
+ resp.raise_for_status()
+ #print(json.dumps(resp.json(), sort_keys=True, indent=2)
def main():
parser = argparse.ArgumentParser(
diff --git a/update.sh b/update.sh
new file mode 100755
index 0000000..668e415
--- /dev/null
+++ b/update.sh
@@ -0,0 +1,6 @@
+#!/usr/bin/env bash
+
+set -x
+
+instaloader --fast-update --no-compress-json extraordinaryleastsquares
+ls extraordinaryleastsquares/2020-0*.json | parallel -j1 ./reupload.py {}