Skip to content

Instantly share code, notes, and snippets.

View onedebos's full-sized avatar

Adebola Adeniran onedebos

View GitHub Profile
const express = require("express");
const app = express();
const cors = require("cors");
app.use(express.json());
app.use(cors());
const axios = require("axios");
const cheerio = require("cheerio");
// accepts the URL of an instagram page
const getVideo = async url => {
// calls axios to go to the page and stores the result in the html variable
const html = await axios.get(url);
// calls cheerio to process the html received
const $ = cheerio.load(html.data);
// searches the html for the videoString
const videoString = $("meta[property='og:video']").attr("content");
// returns the videoString
return videoString;
// the callback is an async function
app.post("/api/download", async (request, response) => {
console.log("request coming in...");
try {
// call the getVideo function, wait for videoString and store it
// in the videoLink variable
const videoLink = await getVideo(request.body.url);
// if we get a videoLink, send the videoLink back to the user
if (videoLink !== undefined) {
const app = require("./scraper");
const supertest = require("supertest");
const api = supertest(app);
// groups tests. the 10,000 value increases the timeout from the default 5000ms
describe("getting video urls from instagram pages", () => {
// each test goes in here
}, 10000);
describe("getting video urls from instagram pages", () => {
// first test
test("a url with the correct link returns an mp4 video link", async () => {
const pageUrl = {
url:
"https://www.instagram.com/p/CA5CsiZJMEJ/?utm_source=ig_web_copy_link"
};
// supertest makes the requests and stores the
// response in the result variable
@onedebos
onedebos / App.js
Last active February 24, 2025 13:46
import React, { useState, useEffect } from "react";
import axios from "axios";
const App = () => {
const [username, setUsername] = useState("");
const [password, setPassword] = useState("");
const [user, setUser] = useState();
useEffect(() => {
const loggedInUser = localStorage.getItem("user");
@onedebos
onedebos / index.html
Created June 30, 2020 21:24
How to center elements with css and flexbox
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Document</title>
<link href="styles.css" rel="stylesheet" />
<link
href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700&display=swap"
rel="stylesheet"
body {
min-height: 100vh;
background-color: wheat;
font-family: "Nunito", sans-serif;
display: flex;
justify-content: center;
align-items: center;
}
.card {
@onedebos
onedebos / App.jsx
Last active July 21, 2023 10:47
How to implement a load more button in React
import React, { useState, useEffect } from "react";
import Posts from "./Posts";
import posts from "./postsArray";
const postsPerPage = 3;
let arrayForHoldingPosts = [];
const App = () => {
const [postsToShow, setPostsToShow] = useState([]);
const [next, setNext] = useState(3);