-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
78 changed files
with
3,580 additions
and
2,616 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
on: # todo | ||
pull_request: | ||
branches: | ||
- "main" | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
docs: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- run: pipx install poetry | ||
- uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.10" | ||
cache: "poetry" | ||
- run: poetry install | ||
|
||
- run: poetry run pydoc-markdown | ||
|
||
- run: poetry run mkdocs gh-deploy --force | ||
working-directory: docs/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,3 +11,6 @@ htmlcov/ | |
.env | ||
|
||
state.json | ||
coinmarket.json | ||
|
||
docs/build |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
[data-md-color-scheme="slate"] { | ||
--md-primary-fg-color: #2e303e; /* Panel */ | ||
--md-default-bg-color: #2e303e; /* BG */ | ||
--md-typeset-a-color: #8e91aa; | ||
--md-accent-fg-color: #658eda | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# hNhM book | ||
![Visits](https://api.visitorbadge.io/api/combined?path=marchinho11%2Fhnhm%2Fdocs&label=Visits&labelColor=%23000000&countColor=%2347c21a&style=flat&labelStyle=none) | ||
|
||
**hNhM**(highly Normalized hybrid Model) – data modeling methodology based on Anchor modeling and Data Vault. Implementation of this package is based on report **"How we implemented our data storage model — highly Normalized hybrid Model"** by Evgeny Ermakov and Nikolai Grebenshchikov. | ||
[1) Yandex Report, habr.com](https://habr.com/ru/company/yandex/blog/557140/). [2) SmartData Conference, youtube.com](https://youtu.be/2fPqDvHsd0w) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Init hNhM | ||
Create the `__hnhm__.py` file with the following contents: | ||
```python | ||
# __hnhm__.py | ||
from hnhm import PostgresPsycopgSql | ||
|
||
sql = PostgresPsycopgSql( | ||
database="coinmarket", | ||
user="hnhm", | ||
password="123", # replace it with an environment variable in the future :) | ||
port=5433, | ||
) | ||
``` | ||
|
||
This `sql` object will help us to generate and execute SQL queries in the database. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
# Intro |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# Raw Data | ||
Create the `etl__raw.py` file. It does the following: | ||
- Fetch the latest currencies | ||
- Create the table in the database | ||
- Insert data | ||
|
||
```python | ||
# etl__raw.py | ||
import os | ||
|
||
import requests | ||
from psycopg2.extras import Json | ||
|
||
from tutorial.__hnhm__ import sql | ||
|
||
COINMARKET_TOKEN = os.environ["COINMARKET_TOKEN"] | ||
|
||
|
||
def get_listings() -> list[dict]: | ||
r = requests.get( | ||
"https://pro-api.coinmarketcap.com/v1/cryptocurrency/listings/latest", | ||
headers={"X-CMC_PRO_API_KEY": COINMARKET_TOKEN}, | ||
) | ||
assert r.status_code == 200 | ||
|
||
data = r.json() | ||
|
||
return [ | ||
{"timestamp": data["status"]["timestamp"], "listing": listing} | ||
for listing in data["data"] | ||
] | ||
|
||
|
||
def save_listings(listings: list[dict]): | ||
sql.execute( | ||
""" | ||
CREATE TABLE IF NOT EXISTS raw_listings( | ||
id SERIAL PRIMARY KEY, | ||
data JSONB | ||
) | ||
""" | ||
) | ||
|
||
sql.execute_many( | ||
""" | ||
INSERT INTO | ||
raw_listings(data) | ||
VALUES | ||
(%s) | ||
""", | ||
((Json(listing),) for listing in listings), | ||
) | ||
|
||
|
||
if __name__ == "__main__": | ||
listings = get_listings() | ||
save_listings(listings) | ||
print(f"Successfully saved: {len(listings)} listings!") | ||
|
||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
# Setup | ||
## Setup CoinMarket account | ||
[Create](https://coinmarketcap.com/api/) free account to work with the CoinMarket API. | ||
|
||
## Setup Python | ||
* Create a directory for the guide: | ||
```shell | ||
mkdir hnhm_guide | ||
cd hnhm_guide | ||
``` | ||
* Install Python with version `>= 3.10`. | ||
* Create virtualenv (personally, I prefer [poetry](https://python-poetry.org/)): | ||
```shell | ||
python3.10 -m virtualenv venv | ||
source ./venv/bin/activate | ||
``` | ||
* Create the file `requirements.txt`: | ||
```text | ||
# requirements.txt | ||
requests==2.31.0 | ||
hnhm | ||
``` | ||
* Install packages: | ||
```shell | ||
pip install -r requirements.txt | ||
``` | ||
|
||
File layout at the end of current step: | ||
``` | ||
. | ||
├── requirements.txt | ||
└── venv | ||
``` | ||
|
||
## Setup Postgres | ||
Let's set up Postgres database. You could use the following `docker-compose.yml` file to run Postgres: | ||
|
||
```yaml | ||
# docker-compose.yml | ||
version: "3.9" | ||
|
||
volumes: | ||
postgres_data: { } | ||
|
||
services: | ||
postgres: | ||
image: postgres:15 | ||
volumes: | ||
- "postgres_data:/var/lib/postgresql/data" | ||
ports: | ||
- "5433:5432" | ||
environment: | ||
POSTGRES_DB: coinmarket | ||
POSTGRES_USER: hnhm | ||
POSTGRES_PASSWORD: 123 | ||
``` | ||
|
||
Run Postgres with the following command: | ||
```shell | ||
docker-compose up -d | ||
|
||
# [+] Running 3/3 | ||
# ✔ Network hnhm_guide_default Created 0.1s | ||
# ✔ Volume "hnhm_guide_postgres_data" Created 0.0s | ||
# ✔ Container hnhm_guide-postgres-1 Started | ||
``` | ||
|
||
Now you should have access to the `coinmarket` database: | ||
```shell | ||
psql -h localhost -p 5433 -U hnhm coinmarket | ||
# Password for user hnhm: 123 | ||
|
||
~# \dt | ||
# Did not find any relations. | ||
``` | ||
|
||
File layout at the end of current step: | ||
``` | ||
. | ||
├── docker-compose.yml | ||
├── requirements.txt | ||
└── venv | ||
``` |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.