Skip to content

Instantly share code, notes, and snippets.

View lafftar's full-sized avatar

Tibabalase Oludemi lafftar

View GitHub Profile
@lafftar
lafftar / spooky_inheritance_in_python.py
Created August 23, 2022 07:44
This file is to illustrate that child classes have a different base class object than their parent.
"""
This test is to illustrate that child classes have a different base class object as their parent.
"""
class Monitor:
reqs_sent = 0
import sys
from pathlib import Path
def get_project_root() -> str:
"""
This fx is super important!
Literally everything acts up if this isn't good.
"""
if getattr(sys, 'frozen', False):
@lafftar
lafftar / terminal.py
Created May 11, 2022 14:09
terminal.py
import sys
from datetime import datetime
from os import system
from typing import Any
from colorama import Back, Style, Fore
def update_title(terminal_title, force: bool = False):
if not force:
from json import dumps, JSONDecodeError, loads
from typing import Union
import httpx
from bs4 import BeautifulSoup
from colorama import Fore, Back, Style
from playwright import async_api
from utils.root import get_project_root
from utils.terminal import color_wrap
def wrap_back(text: [str, int, float, Any], color: str = Back.GREEN) -> str:
    """

    :param text: stuff that can be transformed to string
    :param color: really a AnsiCodes/AnsiBack
    :return: your wrapped string
    """
    return f'{color}{text}{Style.RESET_ALL}'
 
@lafftar
lafftar / main.py
Created February 15, 2022 18:38
Removing default headers from aiohttp
from aiohttp import ClientSession, ClientRequest
class CustomRequestClass(ClientRequest):
DEFAULT_HEADERS = {}
pass
async def main():
async with ClientSession(headers={"User-Agent": 'Dario\'sGodBot', "Host": "httpbin.org"},
request_class=CustomRequestClass) \
as sesh:
res = await sesh.request(method='GET', url='http://httpbin.org/get')
@lafftar
lafftar / gist:7b0313b39b8077e4f27c68ae1ae8d6c9
Created August 30, 2020 12:04
GTA Cities Real Estate - 27 Cities - Quick Data Study - 5
from requests import Session
from pandas import DataFrame
from bs4 import BeautifulSoup as bs
from time import time
t1 = time()
main_session = Session()
page = main_session.get('https://en.wikipedia.org/wiki/Greater_Toronto_and_Hamilton_Area').content
page = bs(page, 'lxml')
dump = []
@lafftar
lafftar / gist:9cd3e18906adec477d9cfbefa04cec1b
Created August 30, 2020 11:55
GTA Cities Real Estate - 27 Cities - Quick Data Study - 4
dump.append({
"City": element.text,
"Average Property Price": avg_prop_price,
"10 Year Rate of Change": ten_years_roc,
"5 Year Rate of Change": five_years_roc,
"1 Year Rate of Change": one_year_roc,
"3 Bedroom Home Price": three_bed_home,
"Url": url
})
print(f"Done scraping {element.text}")
@lafftar
lafftar / gist:30bf3f5f076abc79f18d17f3013d038c
Created August 30, 2020 11:51
GTA Cities Real Estate - 27 Cities - Quick Data Study - 3
url = f"https://{'-'.join(element.text.split()).lower()}.listing.ca/real-estate-prices-by-community.htm"
print(url)
resp = main_session.get(url)
print(resp.url)
listing_ca_page = bs(resp.content, 'lxml')
three_bed_home = listing_ca_page.find('a', attrs={'href': '/3-bedroom-detached-home'
'-prices-by-community.htm'})\
.next.next.text.strip() # avg price of detached 3 bedroom home
@lafftar
lafftar / gist:fc03524fd3bdac2ae9a87cae50a3d546
Last active August 30, 2020 11:38
GTA Cities Real Estate - 27 Cities - Quick Data Study - 1
from requests import Session
from pandas import DataFrame
from bs4 import BeautifulSoup as bs
from time import time
t1 = time()
main_session = Session()
page = main_session.get('https://en.wikipedia.org/wiki/Greater_Toronto_and_Hamilton_Area').content
page = bs(page, 'lxml')
dump = []