Skip to content

Instantly share code, notes, and snippets.

@avendesta
Last active December 14, 2020 14:44
Show Gist options
  • Save avendesta/a88286c1fa7d77e177d98384988c0b9d to your computer and use it in GitHub Desktop.
Save avendesta/a88286c1fa7d77e177d98384988c0b9d to your computer and use it in GitHub Desktop.
Medium automation with Puppeteer
const puppeteer = require('puppeteer');
async function republish() {
const edit_url = "https://medium.com/p/96fe4266534f/edit"; // Replace this with your post edit path
await page.goto(edit_url);
await page.waitForSelector("p[name='a46a']");
await page.$eval("p[name='a46a']", e => e.innerHTML = "The current time and date in NY city is "+(new Date()).toLocaleString('en-US', { timeZone: 'America/New_York' }));
const sleep = require('util').promisify(setTimeout);
await sleep(6000);
await page.click("button[data-action='republish']");
};
let browser;
let page;
(async () => {
try {
browser = await puppeteer.launch({ headless: true, args: ["--no-sandbox"] });
page = await browser.newPage();
await page.setUserAgent('Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4298.0 Safari/537.36');
const token_url = "https://medium.com/m/callback/email?token="+process.env.LOGIN_TOKEN+"&operation=login&state=medium";
await page.goto(token_url);
await setInterval(republish, 1000 * 60 * 20); // every 20 minutes
await page.waitForSelector("title");
} catch (e) { console.log(e) };
})()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment