Nihilate / Roboragi

Roboragi is a Reddit bot which helps link anime, manga, and other Japanese media.
GNU Affero General Public License v3.0
167 stars 30 forks source link

Make AnimePlanet.py more PEP8 compliant #51

Closed reillysiemens closed 6 years ago

reillysiemens commented 6 years ago

PEP8 compliance (according to flake8) before and after the changes in this PR. This is part of addressing #16.

(roboragi) [0:36:22] tucker@khanti:~/Projects/Roboragi git:(master) $ flake8 roboragi/AnimePlanet.py
roboragi/AnimePlanet.py:34:80: E501 line too long (98 > 79 characters)
roboragi/AnimePlanet.py:46:80: E501 line too long (90 > 79 characters)
roboragi/AnimePlanet.py:57:80: E501 line too long (118 > 79 characters)
roboragi/AnimePlanet.py:60:80: E501 line too long (120 > 79 characters)
roboragi/AnimePlanet.py:69:80: E501 line too long (87 > 79 characters)
roboragi/AnimePlanet.py:74:5: E722 do not use bare except'
roboragi/AnimePlanet.py:79:80: E501 line too long (178 > 79 characters)
roboragi/AnimePlanet.py:82:80: E501 line too long (98 > 79 characters)
roboragi/AnimePlanet.py:95:80: E501 line too long (90 > 79 characters)
roboragi/AnimePlanet.py:106:80: E501 line too long (118 > 79 characters)
roboragi/AnimePlanet.py:109:80: E501 line too long (120 > 79 characters)
roboragi/AnimePlanet.py:118:80: E501 line too long (87 > 79 characters)
roboragi/AnimePlanet.py:123:5: E722 do not use bare except'
(roboragi) [0:36:25] tucker@khanti:~/Projects/Roboragi git:(master) $ git co pep8-anime-planet 
Switched to branch 'pep8-anime-planet'
(roboragi) [0:36:39] tucker@khanti:~/Projects/Roboragi git:(pep8-anime-planet) $ flake8 roboragi/AnimePlanet.py
(roboragi) [0:36:43] tucker@khanti:~/Projects/Roboragi git:(pep8-anime-planet) $

While I was in here I also made the URL generation a little safer and cleaner using urljoin and quote. This demonstrates that URL generation should still work the same in Python 2 and Python 3.

# url_example.py
from sys import version_info

PY2 = version_info.major == 2

BASE_URL = 'https://www.anime-planet.com'

if PY2:
    from urllib import quote
    from urlparse import urljoin
else:
    from urllib.parse import quote, urljoin

def url():
    return urljoin(BASE_URL, '/anime/all?name=' + quote('Hello World!'))

if __name__ == '__main__':
    print(url())
[0:47:29] tucker@khanti:/tmp/url-example $ [ $(python url_example.py) == $(python3 url_example.py) ] && echo "They're the same."
They're the same.
[0:47:30] tucker@khanti:/tmp/url-example $

For future PRs (or for this one, I guess) should I be concerned with writing Python 2/Python 3 compatible code, or can I safely write Python 3 only code?

Nihilate commented 6 years ago

Looks good. You can safely stick with purely supporting Python 3. It's currently running as 3.6.5, but I'm happy to upgrade if you're after some 3.7.0 features.

reillysiemens commented 6 years ago

Python 3.6.5 is plenty modern enough for most of the changes I've got in mind. Now that I know that's what's running under the hood I may take more advantage of those features (especially f-strings to keep strings shorter). There might be cause to take advantage of some of the 3.7.0 features (maybe data classes?) at a later date, but I don't think that's necessary now.

I'll probably also suggest the inclusion of type annotations where possible as the Great Roboragi Cleanup progresses. :grin:

Nihilate commented 6 years ago

For sure, that sounds like a good idea - I've created #52 to cover it off.