PushBullet – Communicatie met Python
Als je eenmaal een PushBullet API key hebt (via je accountgegevens op de website), kun je deze gebruiken om de PushBullet API aan te spreken om bijvoorbeeld berichten naar een apparaat te sturen!
Wat heb je nodig?
1) Pushbullet account
2) Python 2 of 3
3) Python PIP package manager (Synology NAS)
Om moeite te besparen is er al een PushBullet Python Script (pyPushBullet) geschreven door Azelphur @ GitHub, deze bibliotheek kun je eenvoudig laden en aanroepen in een Python script, maar er moeten eerst aanvullende python bibliotheken geinstaleerd worden met behulp van PIP.
PIP websocket-client
De ‘websocket-client’ bibliotheek installeer je met het commando: pip install websocket-client
1 2 3 4 5 6 7 8 9 10 11 12 |
Collecting websocket-client Downloading websocket-client-0.23.0.tar.gz (195kB) 100% |################################| 196kB 743kB/s Requirement already satisfied (use --upgrade to upgrade): six in /lib/python2.7/site-packages (from websocket-client) Collecting backports.ssl-match-hostname (from websocket-client) Downloading backports.ssl_match_hostname-3.4.0.2.tar.gz Installing collected packages: backports.ssl-match-hostname, websocket-client Running setup.py install for backports.ssl-match-hostname Running setup.py install for websocket-client changing mode of build/scripts-2.7/wsdump.py from 644 to 755 changing mode of /usr/bin/wsdump.py to 755 Successfully installed backports.ssl-match-hostname-3.4.0.2 websocket-client-0.23.0 |
PIP requests
De ‘requests’ bibliotheek installeer je met het commando: pip install requests
1 2 3 4 5 6 |
Collecting requests Downloading requests-2.5.1-py2.py3-none-any.whl (464kB) 100% |################################| 466kB 696kB/s Installing collected packages: requests Successfully installed requests-2.5.1 |
PIP libmagic
De ‘libmagic’ bibliotheek installeer je met het commando: pip install libmagic
1 2 3 4 5 |
Collecting libmagic Downloading libmagic-1.0.tar.gz Installing collected packages: libmagic Running setup.py install for libmagic Successfully installed libmagic-1.0 |
PIP Python magic
De ‘Python magic’ bibliotheek installeer je met het commando: pip install python-magic
1 2 3 4 5 |
Collecting python-magic Downloading python-magic-0.4.6.tar.gz Installing collected packages: python-magic Running setup.py install for python-magic Successfully installed python-magic-0.4.6 |
PIP Pushbullet (optioneel?)
De ‘Pushbullet’ bibliotheek installeer je met het commando: pip install pushbullet.py
1 2 3 4 5 6 7 8 9 10 |
Collecting pushbullet.py Downloading pushbullet.py-0.5.0.tar.gz Requirement already satisfied (use --upgrade to upgrade): requests>=1.0.0 in /lib/python2.7/site-packages (from pushbullet.py) Requirement already satisfied (use --upgrade to upgrade): python-magic in /lib/python2.7/site-packages (from pushbullet.py) Requirement already satisfied (use --upgrade to upgrade): websocket-client in /lib/python2.7/site-packages (from pushbullet.py) Requirement already satisfied (use --upgrade to upgrade): six in /lib/python2.7/site-packages (from websocket-client->pushbullet.py) Requirement already satisfied (use --upgrade to upgrade): backports.ssl-match-hostname in /lib/python2.7/site-packages (from websocket-client->pushbullet.py) Installing collected packages: pushbullet.py Running setup.py install for pushbullet.py Successfully installed pushbullet.py-0.5.0 |
Als ik daarna de bibliotheek gebruik, dan krijg ik de foutmelding:
1 2 3 4 5 6 7 8 |
Traceback (most recent call last): File "/usr/pushbullet/pushbullet_cmd.py", line 18, in <module> from pushbullet import PushBullet File "/usr/pushbullet/pushbullet.py", line 17, in <module> import magic File "/usr/lib/python2.7/site-packages/magic.py", line 161, in <module> raise ImportError('failed to find libmagic. Check your installation') ImportError: failed to find libmagic. Check your installation |
Ik heb verschillende fora afgezocht, maar heb nog geen oplossing kunnen vinden….jij?