Skip to content

Instantly share code, notes, and snippets.

View Ze1598's full-sized avatar

José Fernando Costa Ze1598

  • Porto, Portugal
View GitHub Profile
import streamlit as st
from notion_api import *
import os
page_name = os.path.basename(__file__).replace(".py", "")
st.set_page_config(
page_title = page_name
)
import streamlit as st
import requests
NOTION_KEY = st.secrets["NOTION_KEY"]
BASE_PAGE_ID = "10f16f5e14c18095863ccadd6d9140de"
def get_child_pages(page_id, token):
url = f"https://api.notion.com/v1/blocks/{page_id}/children"
headers = {
"Authorization": f"Bearer {token}",
@Ze1598
Ze1598 / 1_download_data.py
Last active April 26, 2022 22:40
SP500 Forecast sourcing data
#from pandas_datareader import data as web
def download_data(tickers, start_date, end_date):
for ticker in tickers:
try:
print(f'Downloading {ticker}')
# Download data from Yahoo
temp_df = web.DataReader(ticker, 'yahoo', start_date, end_date)
# Create a column with only the ticker symbol
temp_df["Ticker"] = ticker
@Ze1598
Ze1598 / gems.py
Last active April 25, 2022 15:43
Falling gems animation with PyGame
import pygame
from random import randint, choice
# RGB colours
BLACK = (0, 0,0)
WHITE = (255, 255, 255)
GREEN = (44, 205, 23)
RED = (216, 10, 0)
BLUE = (27, 64, 255)
PURPLE = (121, 0, 234)
@Ze1598
Ze1598 / append_ws_v2.py
Created November 28, 2021 16:39
Add a worksheet to an Excel workbook (Version 2)
import pandas as pd
import openpyxl as pxl
from openpyxl.utils.dataframe import dataframe_to_rows
# Name of the workbook we'll be using
filename = 'test_wb.xlsx'
# For demo purposes, create a new 1-sheet workbook
# DataFrame to be inserted in the first worksheet
firstMockDF = pd.DataFrame({
@Ze1598
Ze1598 / save_scraped_data_in_df.py
Last active July 28, 2021 23:34
Arknights - scrape operator level up stats
# Imports
# (...)
# selenium set up
# (...)
# scrape dictionary of characters and output as pickle
# (...)
# Running dataframe to collect operator data into
@Ze1598
Ze1598 / scrape_all_character_pages.py
Created July 28, 2021 23:17
Arknights - scrape operator level up stats
# Imports
# (...)
# selenium set up
# (...)
# scrape dictionary of characters and output as pickle
# (...)
# op_dict is the dictionary with all characters and their URLs
@Ze1598
Ze1598 / get_character_list.py
Last active July 28, 2021 22:41
Arknights - scrape operator level up stats
import requests
import pickle
from bs4 import BeautifulSoup
req = requests.get("https://gamepress.gg/arknights/tools/interactive-operator-list")
soup = BeautifulSoup(req.content, "lxml")
# Get all the table cells (<td>) with information about the operators
op_list = soup.find_all("td", class_="operator-cell")
op_dict = {}
@Ze1598
Ze1598 / level_up_char.py
Last active July 28, 2021 19:18
Arknights - scrape operator level up stats
# imports, driver variable set up and loading a character page
# (...)
def get_stats_per_level(num_levels):
for i in range(num_levels):
# Code to read stats (see previous code snippet)
# (...)
# Get the arrow to increase operator level
@Ze1598
Ze1598 / read_level_stats.py
Created July 28, 2021 18:45
Arknights - scrape operator level up stats
# imports, driver variable set up and loading a character page
# (...)
# First thing we need before reading data: decrease the operator level (even if it is already at the lowest level possible)
# Otherwise some stats may be missing
decrease_level_button = driver.find_element_by_class_name("fa-arrow-left")
decrease_level_button.click()
# Read the opreator class
operator_class = driver.find_element_by_class_name("profession-title").text.strip()