add utils
This commit is contained in:
parent
05698fa938
commit
cbcb7445c7
1
utils/allStations.json
Normal file
1
utils/allStations.json
Normal file
File diff suppressed because one or more lines are too long
43
utils/default.nix
Normal file
43
utils/default.nix
Normal file
@ -0,0 +1,43 @@
|
||||
with import <nixpkgs> { };
|
||||
|
||||
let
|
||||
pythonPackages = python3Packages;
|
||||
in pkgs.mkShell rec {
|
||||
name = "impurePythonEnv";
|
||||
venvDir = "./.venv";
|
||||
buildInputs = [
|
||||
# A python interpreter including the 'venv' module is required to bootstrap
|
||||
# the environment.
|
||||
pythonPackages.python
|
||||
|
||||
# This execute some shell code to initialize a venv in $venvDir before
|
||||
# dropping into the shell
|
||||
pythonPackages.venvShellHook
|
||||
|
||||
# Those are dependencies that we would like to use from nixpkgs, which will
|
||||
# add them to PYTHONPATH and thus make them accessible from within the venv.
|
||||
pythonPackages.numpy
|
||||
pythonPackages.requests
|
||||
pythonPackages.numba
|
||||
|
||||
# In this particular example, in order to compile any binary extensions they may
|
||||
# require, the python modules listed in the hypothetical requirements.txt need
|
||||
# the following packages to be installed locally:
|
||||
taglib
|
||||
openssl
|
||||
git
|
||||
libxml2
|
||||
libxslt
|
||||
libzip
|
||||
zlib
|
||||
];
|
||||
|
||||
# Now we can execute any commands within the virtual environment.
|
||||
# This is optional and can be left out to run pip manually.
|
||||
postShellHook = ''
|
||||
export PYTHONPATH=`pwd`/$VENV/${python.sitePackages}/:$PYTHONPATH
|
||||
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:${pkgs.ncurses}/lib
|
||||
pip install -r requirements.txt
|
||||
'';
|
||||
|
||||
}
|
35
utils/generateBlurhashes.py
Normal file
35
utils/generateBlurhashes.py
Normal file
@ -0,0 +1,35 @@
|
||||
import blurhash
|
||||
import json
|
||||
import requests
|
||||
import PIL
|
||||
|
||||
with open('top100stations.json') as json_data:
|
||||
allStations = json.load(json_data)
|
||||
|
||||
r = None
|
||||
|
||||
stationsBlurHash = {'stations': []}
|
||||
|
||||
for station in allStations:
|
||||
|
||||
stationuuid = station['stationuuid']
|
||||
stationfavicon = station['favicon']
|
||||
|
||||
try:
|
||||
r = requests.get(stationfavicon, allow_redirects=True)
|
||||
except:
|
||||
pass
|
||||
if (r):
|
||||
if (r.status_code == 200):
|
||||
open('images/'+stationuuid, 'wb').write(r.content)
|
||||
imageFile = 'images/'+stationuuid
|
||||
try:
|
||||
blurHash = blurhash.encode(imageFile, x_components=4, y_components=4)
|
||||
print(station['stationuuid'], " - ", stationfavicon, " - ", blurHash)
|
||||
stationsBlurHash['stations'].append({stationuuid: blurHash})
|
||||
except:
|
||||
pass
|
||||
|
||||
with open('stations100BlurHash.json', 'w') as the_file:
|
||||
json.dump(stationsBlurHash, the_file)
|
||||
the_file.close()
|
2
utils/requirements.txt
Normal file
2
utils/requirements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
requests
|
||||
blurhash-python
|
Loading…
Reference in New Issue
Block a user