Skip to content

Instantly share code, notes, and snippets.

View aaravm4's full-sized avatar
🎃
Hi!

Aarav M aaravm4

🎃
Hi!
View GitHub Profile
@aaravm4
aaravm4 / elections.py
Created August 2, 2022 17:13
Scraping election results from 1824 - 2020
# Scraping "The American Presidency Project" @ https://www.presidency.ucsb.edu/statistics/elections/
from bs4 import BeautifulSoup as soupify
import requests
BASE_URL = "https://www.presidency.ucsb.edu/statistics/elections"
election_dict = {} # For each election year, contains --> KEY [year] : VALUE [dictionary of states mapped to chosen candidate]
@aaravm4
aaravm4 / weather.py
Last active August 3, 2022 01:39
Scrapes weather information based on a user-provided zip code
# 2 years old
from requests import get
from bs4 import BeautifulSoup as soupify
flag = True
zip_code = input("Zip Code: ")
url = 'https://weather.com/weather/today/l/' + zip_code + ':4:US'
page_source = get(url)
content = soupify(page_source.content, "html.parser")
@aaravm4
aaravm4 / diseases.csv
Created August 2, 2022 13:02
Various disease info from the US
We can't make this file beautiful and searchable because it's too large.
Entity,Code,Year,Deaths - Unsafe water source - Sex: Both - Age: All Ages (Number),Deaths - Unsafe sanitation - Sex: Both - Age: All Ages (Number),Deaths - No access to handwashing facility - Sex: Both - Age: All Ages (Number),Deaths - Household air pollution from solid fuels - Sex: Both - Age: All Ages (Number),Deaths - Non-exclusive breastfeeding - Sex: Both - Age: All Ages (Number),Deaths - Discontinued breastfeeding - Sex: Both - Age: All Ages (Number),Deaths - Child wasting - Sex: Both - Age: All Ages (Number),Deaths - Child stunting - Sex: Both - Age: All Ages (Number),Deaths - Low birth weight for gestation - Sex: Both - Age: All Ages (Number),Deaths - Secondhand smoke - Sex: Both - Age: All Ages (Number),Deaths - Alcohol use - Sex: Both - Age: All Ages (Number),Deaths - Drug use - Sex: Both - Age: All Ages (Number),Deaths - Diet low in fruits - Sex: Both - Age: All Ages (Number),Deaths - Diet low in vegetables - Sex: Both - Age: All Ages (Number),Deaths - Unsafe sex - Sex: Both - Age: All Ages (Number
@aaravm4
aaravm4 / diseases.py
Created August 2, 2022 13:02
Data processing using "csv" module
import csv
with open('diseases.csv', mode='r') as csv_file:
csv_reader = csv.DictReader(csv_file)
line_count = 0
for row in csv_reader:
if row["Entity"] == "United States":
if int(row["Year"]) < 1999: continue
print(row["Year"])
@aaravm4
aaravm4 / fifa19.py
Created August 2, 2022 12:51
Web scraping players from a FIFA 19 database
import requests
from bs4 import BeautifulSoup as soupify
import pandas
############ NOTE: ###########
################
# DATA IS IN THE OUT.CSV FILE!
# RUNNING THE PROGRAM WILL TAKE AT LEAST 15 MINUTES TO SCAN 420 ENTRIES
# TO SCAN ALL 655 IT TOOK 23:12 MINUTES.
################
@aaravm4
aaravm4 / fifa19.csv
Created November 19, 2020 02:49
Random FIFA19 Data
We can't make this file beautiful and searchable because it's too large.
,Name,Rating,Potential,Age,Club,Position
0,Lionel Messi,94,94,33,FC Barcelona,RW
1,Cristiano Ronaldo,93,93,35,Juventus,ST
2,Neymar Jr,92,92,28,Paris Saint-Germain,LW
3,Virgil van Dijk,91,92,29,Liverpool,CB
4,Jan Oblak,91,93,27,Atlético Madrid,GK
5,Kevin De Bruyne,91,91,29,Manchester City,CAM
6,Robert Lewandowski,91,91,32,FC Bayern München,ST
7,Eden Hazard,91,91,29,Real Madrid,LW
8,Alisson,90,91,27,Liverpool,GK
@aaravm4
aaravm4 / out.csv
Last active November 14, 2020 03:27
Random FIFA data for csp
We can't make this file beautiful and searchable because it's too large.
,Name,Rating,Potential,Age,Club,Position
0,Lionel Messi,94,94,33,FC Barcelona,RW
1,Cristiano Ronaldo,93,93,35,Juventus,ST
2,Neymar Jr,92,92,28,Paris Saint-Germain,LW
3,Virgil van Dijk,91,92,29,Liverpool,CB
4,Jan Oblak,91,93,27,Atlético Madrid,GK
5,Kevin De Bruyne,91,91,29,Manchester City,CAM
6,Robert Lewandowski,91,91,32,FC Bayern München,ST
7,Eden Hazard,91,91,29,Real Madrid,LW
8,Alisson,90,91,27,Liverpool,GK
@aaravm4
aaravm4 / transcribe.py
Last active August 9, 2022 15:53
DNA Transcription and Translation
# A Transcription and Translation Python Program
# DNA Strand Here
# Example: ATCGAATACAGATAAATT
dna = "" # contain only from ["A", "C", "G", "T"]
pairs = {"A": "U", "T": "A", "C": "G", "G": "C"}
transcribe = ''.join([pairs[a] for a in dna])
# Finding Proteins
proteins = []
@aaravm4
aaravm4 / isbn.py
Created September 17, 2020 02:59
ISBN Check Digit
# ISBN Check Digit Solution
import sys
import itertools
isbn = input("Type in your ISBN Code: ").strip().replace('-', '')
dig_count = len(isbn)
if dig_count != 12 and dig_count != 9:
print(f"Sorry but I can only evaluate 10-digit or 13-digit ISBN Codes, which need 9 digits or 12 digits respectively.\nYou gave me one with a length of {dig_count}.")