Skip to content

Instantly share code, notes, and snippets.

View paduel's full-sized avatar
🎯
Focusing

paduel

🎯
Focusing
View GitHub Profile
@paduel
paduel / flashscore_live_parser.py
Last active December 5, 2022 04:10
FlashScore Live Events Parser
from requests_html import AsyncHTMLSession
import pandas as pd
from unicodedata import normalize
url = 'https://www.flashscore.com/'
asession = AsyncHTMLSession()
async def get_scores():
@paduel
paduel / wave_started_app.py
Created March 24, 2021 00:08 — forked from mtanco/wave_started_app.py
Starter code I have been using for most new apps
from h2o_wave import main, app, Q, ui, handle_on, on, data
from loguru import logger
def on_startup():
"""
Runs when the app is started, even if there are no browsers connected
:return:
"""
logger.info('http://localhost:10101/')
@paduel
paduel / yahoo_finance_stream.py
Last active May 21, 2020 10:34
Code to get quote streaming from Yahoo Finance
from requests import get
import threading
from time import sleep
from pandas import Series
from datetime import datetime
# Function get information in json format from Yahoo Finance
def stream(
symbol,
callback=None,
@paduel
paduel / folder_to_module_path.py
Created December 13, 2019 15:51
Add the current folder to the Python modules path
import sys
import os
for line in sys.path:
if line.endswith('site-packages'):
print(line)
lib_path = line
file = os.path.join(lib_path, 'accurate_modules.pth')
@paduel
paduel / pandas_logo.py
Created October 27, 2019 00:54
Generate new Pandas logo with Altair
# script to generate the neww pandas logo
# MrEavesXLModOT-Bold font must be installed
import altair as alt
from pandas import DataFrame
source = DataFrame({
'x': [1, 2, 2, 2, 3, 3, 3, 4],
'y': [0, 54.17, 119.6, 157.8, 13.73, 78.13, 116.17, 54.17],
'y2': [167.0, 105.37, 144.17, 209.0, 64.93, 102.7, 167.37, 221.17],
@paduel
paduel / read_hst.R
Created July 6, 2019 16:24
Import Metatrader .hst files to R dataframe
read_hst <- function(filename){
library(anytime)
hst_file <- file(filename, "rb")
version <- readBin(hst_file, integer(), 1, size = 4, endian="little")
head <- readBin(hst_file, character(), 22, endian="little")
symbol <- head[22]
print(paste(symbol, "hst to dataframe"))
datetime <- c()
open <- c()
@paduel
paduel / read_hst.py
Created July 4, 2019 15:11
Importar archivos .hst de Metatrader en Python
def read_hst(filename):
from pandas import DataFrame, to_datetime
from struct import unpack, calcsize, iter_unpack
bint = open(filename, 'rb').read()
head = unpack('<i64s12siiii', bint[:96])
version = head[0]
symbol = head[2].decode("utf-8").split('\x00')[0]
start = 148
if version == 401:
fmt = '<qddddqfq'
@paduel
paduel / new_jupyter_snippet.py
Last active July 2, 2019 11:44
Easily add new snippets for jupyter nbextension.
def new_snippet(name, code):
'''Save a new snippet at json for Snippets nbextesion
Parameters
----------
name : str
Name that will appear in the drop-down list
code : str
String containing the lines of code to be saved.
@paduel
paduel / pi_monitor.py
Created May 9, 2019 19:55
Un breve codigo para descargar el valor de Pi en la divisa deseada de forma continua usando callback.
from requests import get
import threading
from time import sleep
# Función que usa un llamada para tomar la información en formato json de la api pública
def get_pi(callback=None, base='EUR', wait_time=1, verbose=False):
while True:
response = get(
f'https://api.piexchange.io/v1/public/instrument/ticker/PIT{base}')
info_dict = response.json()
@paduel
paduel / read_vc_excel.py
Last active May 3, 2019 16:24
Read a xlxs file from Visualchart data patch into a pandas DataFrame
from pandas import read_excel, to_datetime
def read_vc_excel(io):
"""Read a xlxs file from Visualchart historical data patch
into a pandas DataFrame.
Parameters:
io : str, file descriptor, pathlib.Path, ExcelFile or xlrd.Book
The string could be a URL. Valid URL schemes include http, ftp, s3,
gcs, and file. For file URLs, a host is expected. For instance, a local
file could be /path/to/workbook.xlsx.