Skip to content

Instantly share code, notes, and snippets.

View hendrixroa's full-sized avatar
🏠
Working from home

Hendrix Roa hendrixroa

🏠
Working from home
View GitHub Profile
@hendrixroa
hendrixroa / create_s3_bucket.tf
Created March 21, 2023 02:03
Create s3 bucket using terraform
resource "aws_s3_bucket" "storage_bucket" {
bucket = var.storage_name
tags = {
Name = "storage"
Environment = "Production"
}
lifecycle {
ignore_changes = [tags]
@hendrixroa
hendrixroa / aws_provider.tf
Created March 21, 2023 02:00
Backend configuration for AWS provider using S3 bucket
terraform {
backend "s3" {
bucket = "your bucket to store state"
key = "terraform.state"
region = "us-east-1"
}
required_providers {
aws = {
source = "hashicorp/aws"
@hendrixroa
hendrixroa / main_scraper.ts
Created March 9, 2023 23:04
Main function that invokes scraper code
import { Scraper } from './scraper';
async function bootstrap() {
const scraper = new Scraper();
try {
const data = await scraper.scrape();
console.log(data);
} catch (e) {
console.error('error', e);
@hendrixroa
hendrixroa / merging_data.ts
Created March 9, 2023 23:00
Merging data
const dataMerged = allNamesRepos.map((repo: any, index: number) => {
const obj = {
name: repo.name,
starsToday: allStarsRepos[index].stars,
};
return obj;
});
@hendrixroa
hendrixroa / getting_stars_number.ts
Created March 9, 2023 22:58
Getting stars number from github trending
const regexMatchDigits = /\d+/g;
const allStarArticles = document.querySelectorAll(
'.Box-row .d-inline-block.float-sm-right',
);
const allStarReposArray = Array.from(allStarArticles);
const allStarsRepos = allStarReposArray.map((item: HTMLElement | any) => {
const starDigits = item.innerText.match(regexMatchDigits);
return { stars: Number(starDigits[0]) };
@hendrixroa
hendrixroa / getting_allrepo_stars.ts
Created March 9, 2023 22:49
Get all repos of github trending
const allReposArticles = document.querySelectorAll(
'.Box-row h1.lh-condensed a',
);
const allReposArray = Array.from(allReposArticles);
const allNamesRepos = allReposArray.map((item: HTMLElement | any) => {
return { name: item.innerText };
});
@hendrixroa
hendrixroa / evaluate_function_headless.ts
Created March 9, 2023 22:38
Evaluate page function where you can get all information of the HTML code.
const data = await page.evaluate(() => {
// Your scraping code here
});
@hendrixroa
hendrixroa / getting_headless_and_openurl.ts
Created March 9, 2023 22:29
Getting a headless browser instance and open a url.
const page = await this.browser.getPage();
await page.goto(this.baseURL, {
timeout: 300000,
waitUntil: 'networkidle0',
});
export class Scraper {
protected name: string;
protected baseURL: string;
protected browser = new HeadlessBrowser();
constructor() {
this.name = 'Scraper';
this.baseURL = 'https://github.com/trending';
}
}
@hendrixroa
hendrixroa / close_headless_browser.ts
Created March 9, 2023 21:49
Close function for turning off a window browser
public closeBrowser() {
if (this.browser) {
this.browser.close();
}
}