Skip to content

Instantly share code, notes, and snippets.

View bibhuticoder's full-sized avatar
⌨️
Coding

Bibhuti Poudyal bibhuticoder

⌨️
Coding
View GitHub Profile
const axios = require('axios');
const { JSDOM } = require("jsdom");
const fs = require("fs");
(async () => {
try {
// Go from page 1 to 82
for (let j = 1; j <= 82; j++) {
@bibhuticoder
bibhuticoder / wikipedia.js
Created August 18, 2021 03:46
Eye friendly wikipedia
// load font
var wfScript = document.createElement('script');
wfScript.src = 'https://ajax.googleapis.com/ajax/libs/webfont/1.6.26/webfont.js';
document.head.appendChild(wfScript);
// apply font
setTimeout(() => {
WebFont.load({
google: {
families: ['Roboto']
name: deploy-to-dev-droplet
on:
push:
branches:
- dev
jobs:
deploy-backend:
runs-on: ubuntu-latest
steps:
- name: Deploy backend
# name of github action workflow
name: deploy-to-dev-droplet
on:
push:
branches:
- dev # this script will run when pushed to "dev" branch
jobs:
deploy-frontend:
runs-on: ubuntu-latest #using latest ubuntu to build application
steps:
import cron from 'node-cron';
import instaCacheCron from "./crons/instaCache.cron";
// run immediately after server starts
instaCacheCron();
// update instaPhotos Cache every 3 hours
cron.schedule('0 0 */3 * * *', async () => {
// this method fetches updated Insta images and saves to DB.
await instaCacheCron();
try {
let instaAccessToken = "XXXXXX"; // get from DB
let resp = await axios.get(`https://graph.instagram.com/me/media?fields=media_type,permalink,media_url&access_token=${instaAccessToken}`);
resp = resp.data;
let instaPhotos = resp.data.filter(d => d.media_type === "IMAGE").map(d => d.media_url);
// Got insta photos
} catch (e) {
console.log(e.response.data.error);
}
try {
let oldAccessToken = "XXXXX"; // get from DB
let resp = await axios.get(`https://graph.instagram.com/refresh_access_token?grant_type=ig_refresh_token&access_token=${oldAccessToken}`)
if (resp.data.access_token) {
let newAccessToken = resp.data.access_token;
// save newAccessToken to DB
}
} catch (e) {
console.log("Error=====", e.response.data);
}
import cron from 'node-cron';
import instaRefreshCron from "./crons/instaRefresh.cron";
// run immediately after server starts
instaRefreshCron();
// refresh instaAccessToken eg: weekly(every Sat)
cron.schedule('* * * * * 7', async () => {
await instaRefreshCron();
});
try {
let resp = await axios.get(`https://graph.instagram.com/access_token?grant_type=ig_exchange_token&client_secret=${process.env.INSTA_APP_SECRET}&access_token=${accessToken}`)
accessToken = resp.data.access_token;
// save accessToken to Database
} catch (e) {
console.log("Error=====", e.data);
}
// data from frontend
let code = req.body.code;
let redirectUri = req.body.redirectUri;
let accessToken = null;
try {
// send form based request to Instagram API
let result = await request.post({
url: 'https://api.instagram.com/oauth/access_token',