Skip to content

Instantly share code, notes, and snippets.

View KenoLeon's full-sized avatar

Keno Leon KenoLeon

View GitHub Profile
@KenoLeon
KenoLeon / coingeck_API_Call_Parse.py
Created May 12, 2022 20:41
historical last 100 days
from pycoingecko import CoinGeckoAPI
import datetime as dt
# today in Timestamp
today = dt.datetime.today()
today_unix = today.timestamp()
# today minus 100 days in Timestamp
today_minus_100 = today - dt.timedelta(days=100)
today_minus_100_unix = today_minus_100.timestamp()
@KenoLeon
KenoLeon / API_Call_Parse_02.py
Created May 12, 2022 19:24
API parse example 02
colorAPIResponse = {'result': [[252, 236, 177], [225, 195, 67], [248, 65, 32], [145, 43, 75], [68, 43, 87]]}
# Parse each color from the colorAPIResponse and print it out.
for color in colorAPIResponse['result']:
print(color)
# >>
# [252, 236, 177]
# [225, 195, 67]
@KenoLeon
KenoLeon / API_CAll_Parse_static_02.py
Created May 12, 2022 01:47
Parse Static JSON API respnse
# AccuEeather API call example 5 Day Forecast for
# Mexico City Code: 242560
response = {'Headline': {'EffectiveDate': '2022-05-14T08:00:00-05:00', 'EffectiveEpochDate': 1652533200, 'Severity': 4, 'Text': 'Pleasant this weekend', 'Category': 'mild', 'EndDate': None, 'EndEpochDate': None, 'MobileLink': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?lang=en-us', 'Link': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?lang=en-us'}, 'DailyForecasts': [{'Date': '2022-05-11T07:00:00-05:00', 'EpochDate': 1652270400, 'Temperature': {'Minimum': {'Value': 54.0, 'Unit': 'F', 'UnitType': 18}, 'Maximum': {'Value': 79.0, 'Unit': 'F', 'UnitType': 18}}, 'Day': {'Icon': 3, 'IconPhrase': 'Partly sunny', 'HasPrecipitation': False}, 'Night': {'Icon': 33, 'IconPhrase': 'Clear', 'HasPrecipitation': False}, 'Sources': ['AccuWeather'], 'MobileLink': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?day=1&lang=en-us', 'Link': 'htt
@KenoLeon
KenoLeon / API_CAll_Parse_static.py
Created May 12, 2022 01:29
parse JSON API call static 01
# AccuEeather API call example 5 Day Forecast for
# Mexico City Code: 242560
response = {'Headline': {'EffectiveDate': '2022-05-14T08:00:00-05:00', 'EffectiveEpochDate': 1652533200, 'Severity': 4, 'Text': 'Pleasant this weekend', 'Category': 'mild', 'EndDate': None, 'EndEpochDate': None, 'MobileLink': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?lang=en-us', 'Link': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?lang=en-us'}, 'DailyForecasts': [{'Date': '2022-05-11T07:00:00-05:00', 'EpochDate': 1652270400, 'Temperature': {'Minimum': {'Value': 54.0, 'Unit': 'F', 'UnitType': 18}, 'Maximum': {'Value': 79.0, 'Unit': 'F', 'UnitType': 18}}, 'Day': {'Icon': 3, 'IconPhrase': 'Partly sunny', 'HasPrecipitation': False}, 'Night': {'Icon': 33, 'IconPhrase': 'Clear', 'HasPrecipitation': False}, 'Sources': ['AccuWeather'], 'MobileLink': 'http://www.accuweather.com/en/mx/mexico-city/242560/daily-weather-forecast/242560?day=1&lang=en-us', 'Link': 'htt
@KenoLeon
KenoLeon / coingeck_API_Call.py
Created May 11, 2022 20:24
coingecko api call
from pycoingecko import CoinGeckoAPI
cg = CoinGeckoAPI()
currentBTCPrice = cg.get_price(ids='bitcoin', vs_currencies='usd')
print(currentBTCPrice)
# >> {'bitcoin': {'usd': 29202}}
@KenoLeon
KenoLeon / YFinance_API.py
Created May 11, 2022 01:01
Simple Yfinance API call
import yfinance as yf
# DEFINE TICKER FOR APPLE
aapl = yf.Ticker("AAPL")
# GET HISTORICAL TRADING DATA
print(aapl.history(period="max"))
# AccuWeather API call example 5 Day Forecast for
# Mexico City Code: 242560
import requests
url = "http://dataservice.accuweather.com/forecasts/v1/daily/5day/242560?apikey=YOURAPIKEY"
resp = requests.get(url)
if resp.status_code == 200:
@KenoLeon
KenoLeon / API_Requests_01.py
Last active May 10, 2022 00:53
example of using requests in Python
import requests
from requests.structures import CaseInsensitiveDict
# ENDPOINT:
url = "http://colormind.io/api/"
# Request Format
headers = CaseInsensitiveDict()
headers["Content-Type"] = "application/json"
data = '{"model":"default"}'
@KenoLeon
KenoLeon / PyScript_Matplotlib.html
Last active May 4, 2022 19:54
Pyplot in the browser with Pyscript
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pyplot in the Browser</title>
<link rel="stylesheet" href="https://pyscript.net/alpha/pyscript.css" />
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>
<py-env>
@KenoLeon
KenoLeon / PyscriptToDOM.html
Last active May 4, 2022 00:33
PyScript to DOM writing example
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet"
crossorigin="anonymous">
<script defer src="https://pyscript.net/alpha/pyscript.js"></script>