Skip to content

Instantly share code, notes, and snippets.

@deepakness
deepakness / app.py
Created July 27, 2023 15:41
Scrape the page titles and URLs of Wikipedia search of "insects".
import requests
from bs4 import BeautifulSoup
import csv
BASE_URL = "https://en.wikipedia.org"
SEARCH_URL = "https://en.wikipedia.org/wiki/Special:Search?search=insects&fulltext=Search&ns0=1"
def get_wikipedia_links(search_url):
r = requests.get(search_url)
soup = BeautifulSoup(r.content, 'html.parser')
@deepakness
deepakness / Code.gs
Last active June 29, 2023 05:32
Create comparisons of "Product 1" vs "Product 2" right inside Google Sheets.
// Add the function to main menu
function onOpen() {
var ui = SpreadsheetApp.getUi();
ui.createMenu('🎉')
.addItem("Create Comparisons", "productComparison")
.addToUi();
}
// Function to create comparisons
function productComparison() {
@deepakness
deepakness / Code.gs
Created May 24, 2023 15:46
Extracts Titles/H1 from URLs right inside Google Sheets
function getTitleOrH1(url) {
var response = UrlFetchApp.fetch(url,
{
method: "get",
muteHttpExceptions: true
});
var html = response.getContentText();
var titleMatch = html.match("<title>(.*?)</title>");
var h1Match = html.match("<h1[^>]*>(.*?)</h1>");
@deepakness
deepakness / Code.gs
Created March 23, 2023 08:55
Use Whisper API to transcribe audio right inside Google Sheets. The script takes .mp3 URLs in the column A and outputs transcribed text in the column B.
function transcribeAudio() {
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
var numRows = sheet.getLastRow();
var urlColumn = 1; // Column A
var transcriptColumn = 2; // Column B
var authToken = "YOUR_OPENAI_API"; // Your OpenAI API Token
var model = "whisper-1"; // The Whisper API Model to use
for (var i = 2; i <= numRows; i++) {
var url = sheet.getRange(i, urlColumn).getValue();