Created
September 10, 2019 20:39
-
-
Save lazanet/f9dad44159f4fefe541605f5f4952b2d to your computer and use it in GitHub Desktop.
Reupload instagram page backup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* tslint:disable:no-console */ | |
/* | |
Reuploads all photos on instagram page from page backup. | |
(when fascist mods decide that your satire must be hate speech) | |
sudo apt install node tsc npm | |
sudo npm install instagram-private-api | |
then copy your backup to ./backup | |
tsc main.ts | |
node main.js | |
Enjoy! | |
*/ | |
import { IgApiClient } from 'instagram-private-api'; | |
import * as Bluebird from 'bluebird'; | |
import { readFile } from 'fs'; | |
var fs = require("fs"); | |
const ig = new IgApiClient(); | |
const keypress = async () => { | |
process.stdin.setRawMode(true) | |
return new Promise(resolve => process.stdin.once('data', data => { | |
const byteArray = [...data] | |
if (byteArray.length > 0 && byteArray[0] === 3) { | |
console.log('^C') | |
process.exit(1) | |
} | |
process.stdin.setRawMode(false) | |
resolve() | |
})) | |
} | |
function sleep(ms){ | |
return new Promise(resolve=>{ | |
setTimeout(resolve,ms) | |
}) | |
} | |
async function login() { | |
let username = "IG_USERNAME" | |
let password = "IG_PASSWORD" | |
ig.state.generateDevice(username); | |
await ig.account.login(username, password); | |
} | |
(async () => { | |
await login(); | |
var contents = fs.readFileSync("backup/media.json"); | |
var data = JSON.parse(contents)["photos"]; | |
data.reverse(); | |
for (let i=0; i<data.length; i++) | |
{ | |
let path = "./backup/" + data[i]["path"]; | |
let caption = data[i]["caption"]; | |
console.log(path) | |
const publishResult = await ig.publish.photo({ | |
file: await Bluebird.fromCallback(cb => readFile(path, cb)), | |
caption: caption | |
}); | |
console.log("Done "+ (i+1) + " / " + data.length); | |
sleep(1500) | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment