first commit

This commit is contained in:
Jasper Roloff 2017-06-21 19:55:40 +02:00 committed by Jasper Roloff
commit 744be2ee7d
3 changed files with 202 additions and 0 deletions

141
.gitignore vendored Normal file
View File

@ -0,0 +1,141 @@
# Created by .ignore support plugin (hsz.mobi)
### Python template
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class
# C extensions
*.so
# Distribution / packaging
.Python
env/
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
*.egg-info/
.installed.cfg
*.egg
# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec
# Installer logs
pip-log.txt
pip-delete-this-directory.txt
# Unit test / coverage reports
htmlcov/
.tox/
.coverage
.coverage.*
.cache
nosetests.xml
coverage.xml
*,cover
.hypothesis/
# Translations
*.mo
*.pot
# Django stuff:
*.log
local_settings.py
# Flask stuff:
instance/
.webassets-cache
# Scrapy stuff:
.scrapy
# Sphinx documentation
docs/_build/
# PyBuilder
target/
# Jupyter Notebook
.ipynb_checkpoints
# pyenv
.python-version
# celery beat schedule file
celerybeat-schedule
# SageMath parsed files
*.sage.py
# dotenv
.env
# virtualenv
.venv
venv/
ENV/
# Spyder project settings
.spyderproject
# Rope project settings
.ropeproject
### JetBrains template
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and Webstorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
# User-specific stuff:
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/dictionaries
# Sensitive or high-churn files:
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.xml
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
# Gradle:
.idea/**/gradle.xml
.idea/**/libraries
# Mongo Explorer plugin:
.idea/**/mongoSettings.xml
## File-based project format:
*.iws
## Plugin-specific files:
# IntelliJ
/out/
# mpeltonen/sbt-idea plugin
.idea_modules/
# JIRA plugin
atlassian-ide-plugin.xml
# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

59
cron.py Normal file
View File

@ -0,0 +1,59 @@
import speedtest
import csv
from pushbullet import Pushbullet
# pushbullet API token
access_token = ''
# min download bandwith (bit/s)
download_min = 75000000
# min upload bandwith (bit/s)
upload_min = 25000000
# max ping in ms
ping_max = 30
# disable in production
test_run = False
servers = []
s = speedtest.Speedtest()
s.get_servers(servers)
s.get_best_server()
s.download()
s.upload()
share_url = s.results.share()[:-4]
if s.results.download < download_min or s.results.upload < upload_min or s.results.ping > ping_max or test_run:
pb = Pushbullet(api_key=access_token)
push = pb.push_link("Internet Bandwidth Warning",
share_url,
"down: %d Mb/s\nup: %d Mb/s\nping: %d ms\n" %
(s.results.download/1000000, s.results.upload/1000000, s.results.ping))
results_dict = s.results.dict()
with open('stats.csv', 'a') as csvfile:
writer = csv.writer(csvfile)
writer.writerow([results_dict['timestamp'],
results_dict['download'],
results_dict['upload'],
results_dict['ping'],
results_dict['bytes_sent'],
results_dict['bytes_received'],
results_dict['share'][:-4],
results_dict['server']['url'],
results_dict['server']['lat'],
results_dict['server']['lon'],
results_dict['server']['name'],
results_dict['server']['country'],
results_dict['server']['cc'],
results_dict['server']['sponsor'],
results_dict['server']['id'],
results_dict['server']['url2'],
results_dict['server']['host'],
results_dict['server']['d'],
results_dict['server']['latency']])

2
requirements.txt Normal file
View File

@ -0,0 +1,2 @@
speedtest-cli
pushbullet.py