Skip to content

Instantly share code, notes, and snippets.

@jitsejan
jitsejan / pythonista_supabase.py
Created Apr 27, 2021
Pythonista script to read from Safari and write to Supabase
View pythonista_supabase.py
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 Mar 25, 2021
Simple script that can assume the role after providing the MFA token
View awsassumerole.py
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 Jan 14, 2021
Send automated mail from crawler
View crawlandmail.py
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 Dec 24, 2020
Simple example on how to use xpaths to get data from a website.
View xpath_retrieval.py
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 Sep 5, 2020
Jira lead time extraction
View jira_extract.py
import pandas as pd
import requests
JIRA_TOKEN = "abcdefg12345"
JIRA_URL = "https://jitsejan.atlassian.net/"
JIRA_USER = "mail@jitsejan.com"
# Setup a requests session
rsession = requests.Session()
# New Jira instances authenticate through a token
@jitsejan
jitsejan / Dockerfile
Last active Jan 14, 2021
PySpark, Docker and S3
View Dockerfile
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 Dec 7, 2019
A simple example to demonstrate how I validate source availability by dynamically calling verify functions.
View availabilitychecker.py
""" 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 Dec 5, 2019
boto3, cloudwatch, events
View get_log_events.py
""" 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 Aug 13, 2019
Export a Google sheet to S3
View export_gsheet_to_s3.py
# 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 Aug 9, 2019
Trigger AWS Lambda function
View trigger_lambda.py
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)