Skip to content

Instantly share code, notes, and snippets.

@jitsejan
jitsejan / pythonista_supabase.py
Created April 27, 2021 00:35
Pythonista script to read from Safari and write to Supabase
import appex
import json
import requests
LANGUAGE = "en-gb"
OXFORD_ID = "9acc1234"
OXFORD_KEY = "6baccf388cd6456456326e85054f30aba"
OXFORD_URL = "https://od-api.oxforddictionaries.com/api/v2"
OXFORD_HEADERS = {
"app_id": OXFORD_ID,
@jitsejan
jitsejan / awsassumerole.py
Created March 25, 2021 01:21
Simple script that can assume the role after providing the MFA token
from datetime import datetime, timedelta
import boto3
ACCOUNT_NUMBER = 1234567890
MAX_DURATION = 129600
NUM_DAYS = 30
USER = "jitsejan"
# Prompt user for the MFA token
@jitsejan
jitsejan / crawlandmail.py
Created January 14, 2021 23:15
Send automated mail from crawler
import smtplib
import ssl
import lxml.html
import requests
URL = "https://happiestbaby.co.uk/products/snoo-smart-bassinet"
resp = requests.get(URL)
tree = lxml.html.fromstring(resp.content)
@jitsejan
jitsejan / xpath_retrieval.py
Created December 24, 2020 20:51
Simple example on how to use xpaths to get data from a website.
from dataclasses import dataclass
import lxml.html
import requests
from typing import Iterator
BASE_URL = "https://zelda.gamepedia.com"
HEADERS = {
'User-Agent': 'Mozilla/5.0'
}
@jitsejan
jitsejan / jira_extract.py
Created September 5, 2020 03:05
Jira lead time extraction
import pandas as pd
import requests
JIRA_TOKEN = "abcdefg12345"
JIRA_URL = "https://jitsejan.atlassian.net/"
JIRA_USER = "[email protected]"
# Setup a requests session
rsession = requests.Session()
# New Jira instances authenticate through a token
@jitsejan
jitsejan / Dockerfile
Last active August 18, 2024 09:53
PySpark, Docker and S3
FROM jupyter/pyspark-notebook
USER root
# Add essential packages
RUN apt-get update && apt-get install -y build-essential curl git gnupg2 nano apt-transport-https software-properties-common
# Set locale
RUN apt-get update && apt-get install -y locales \
&& echo "en_US.UTF-8 UTF-8" > /etc/locale.gen \
&& locale-gen
# Add config to Jupyter notebook
COPY jupyter/jupyter_notebook_config.py /home/jovyan/.jupyter/
@jitsejan
jitsejan / availabilitychecker.py
Created December 7, 2019 04:11
A simple example to demonstrate how I validate source availability by dynamically calling verify functions.
""" availabilitychecker.py """
import boto3
import requests
class AvailabilityChecker:
def __init__(self):
self.ssm_client = boto3.client("ssm")
self.session = requests.Session()
@jitsejan
jitsejan / get_log_events.py
Created December 5, 2019 18:24
boto3, cloudwatch, events
""" Get the log events for a log group from CloudWatch """
import boto3
from datetime import datetime, timedelta
import pandas as pd
ACCOUNT = 'prod'
GROUP = '/aws/lambda/lambda-function-prod'
NUM_DAYS = 7
START_TIME = int((datetime.now() - timedelta(days=NUM_DAYS)).timestamp())
@jitsejan
jitsejan / export_gsheet_to_s3.py
Created August 13, 2019 11:44
Export a Google sheet to S3
# Note: make sure the Google Sheet is published to the web first
import boto3
import json
import pandas as pd
import pyarrow
import requests
GOOGLE_URL = "https://spreadsheets.google.com/feeds/list/{key}/{worksheet}/public/full?alt={format}"
GOOGLE_SHEET_ID = '1234567-abcedf'
GOOGLE_SHEET_TITLE = 'My title'
@jitsejan
jitsejan / trigger_lambda.py
Created August 9, 2019 10:39
Trigger AWS Lambda function
import boto3
import json
REGION = "eu-west-1"
ENV = "dev"
FUNCTION_NAME = 'lambda-function-name'
session = boto3.session.Session(profile_name=ENV)
lambda_client = session.client('lambda', REGION)