Retire 'python-pushsafer'

Pushsafer make it easy and safe to get push-notifications in real time on your Android or Windows mobile device, iPhone, iPad and Desktop!

Mit Pushsafer kann man in Echtzeit, einfach und sicher, Push-Benachrichtigungen auf sein iPhone, iPad, Android oder Windows Gerät sowie auf den Desktop senden lassen!

======================
Google Play
App Store
Windows 10 Store
Homepage
2e0byo
Posts: 2
Joined: 25. Oct 2021, 20:11

Retire 'python-pushsafer'

Postby 2e0byo » 25. Oct 2021, 20:26

python-pushsafer is recommended on pushsafer's own website:

https://www.pushsafer.com/en/python

Unfortunately, the code is hopelessly broken:

- State is stored in a global variable, not a class, so you can only ever have one login
- Classes are used as functions
- Client() never does anything with the privatekey argument
- Client has a completely useless empty list (devices) which is never written to
- There is random whitespace all over the place
- Client.send_message has only positional args, so you have to manually set them to `None` to avoid problems.
- Client send_message *incorrectly sends post data as parameters*, thus meaning the library will never work anyway.
- Lots of the logic is implemented in very questionable ways (e.g. using getattr to retrieve requests.post).

I don't know who the developer is, or whether the code is actively developed. I could submit a PR fixing all this (I probably will, now I've been so emphatic about it) but the fact that the library is in a state in which it could never possibly work suggests that nobody actually uses it. Thus I wonder whether there is any point keeping the library around at all? It will likely only get out of sync with the api, and the api is perfectly clear and easy to use without bindings. Thus I suggest just deleting it and updating the python api docs (I'm happy to suggest an update for that if you want).

Incidentally, the python instructions on the api page are needlessly complicated since they don't use requests, which 99.999% of developers are going to do.

Src is at https://github.com/appzer/python-pushsa ... shsafer.py

Note that pushsafer is a great utility and none of this in any way detracts from that: I'm very glad it exists :)

User avatar
admin
Site Admin
Posts: 767
Joined: 1. Dec 2014, 12:41
Location: Germany

Re: Retire 'python-pushsafer'

Postby admin » 26. Oct 2021, 08:41

Hi 2e0byo,

thanks for rewriting the code.
I forked the code and customized it for pushsafer needs. I'am not a python developer!

Can you check the readme, the code blocks are broken!
https://github.com/appzer/python-pushsa ... README.rst

I will check the functionallity after the readme is fixed.
If the script worked as it should, i will publish it to pypi.

Thanks a lot

Kevin
Pushsafer DE: Dir gefällt Service und Support! Dann freuen wir uns auf deine Bewertung!
Pushsafer EN: You like Service and Support! Then we look forward to your review!

Pushsafer.com Website - iOS - Android - Windows 10

2e0byo
Posts: 2
Joined: 25. Oct 2021, 20:11

Re: Retire 'python-pushsafer'

Postby 2e0byo » 26. Oct 2021, 09:57

Oops; I've fixed that and commented on the PR (I'll keep comments about pushsafer for the PR discussion, since you don't want to retire it for now :) ).

The 'python3' documentation:

https://www.pushsafer.com/en/pushapi

Should look something like this IMHO:

Code: Select all

import base64
from pathlib import Path

import requests

# local image from drive
with Path("logo.jpg").open("rb") as f:
    img1 = base64.b64encode(f.read())

# remote image from url
img2_url = (
    "https://www.google.de/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"
)
r = requests.get(img2_url)
img2 = base64.b64encode(r.content)

url = "https://www.pushsafer.com/api"
post_fields = {
    "t": "Test",
    "m": "Test Message",
    "s": 11,
    "v": 3,
    "i": 33,
    "c": "#FF0000",
    "d": "a",
    "u": "https://www.pushsafer.com",
    "ut": "Open Pushsafer",
    "k": "<privatekey>",
    "p1": f"data:image/png;base64,{img2}",
    "p2": f"data:image/png;base64,{img2}",
}

r = requests.post(url, data=post_fields)
print(r.json())
whilst the supplied code did *work*, (as does this) it is much more common to use requests for things like this than to mess around with managing the connection yourself. Even if you want to stick with builtin libraries, the file handling was wrong (files were not closed) and `file` should not be used as a varname.

Once again, thank you for pushsafer, it's a great service! :)

User avatar
admin
Site Admin
Posts: 767
Joined: 1. Dec 2014, 12:41
Location: Germany

Re: Retire 'python-pushsafer'

Postby admin » 26. Oct 2021, 17:10

i updated the pypi package, thanks a lot for your work

Kevin
Pushsafer DE: Dir gefällt Service und Support! Dann freuen wir uns auf deine Bewertung!
Pushsafer EN: You like Service and Support! Then we look forward to your review!

Pushsafer.com Website - iOS - Android - Windows 10


Who is online

Users browsing this forum: No registered users and 2 guests