📜 ⬆️ ⬇️

Checking the karma of a habrahabr.ru user using Python on Android

I love the Python programming language and also love the Android OS. It was a pleasant discovery for me that for this OS there is a full-fledged Python interpreter, but I constantly put off getting to know it. In this article I want to tell about the basic principles of programming in this language for this OS.

SL4A


Preparation for work

First you need to download SL4A and download Python itself. After installing Python, run it and click the install button at the top of the screen. After that all standard libraries and extensions for work on Android will be downloaded. For the convenience of making minor changes, you can download a code editor, which I once wrote about .
')
Source

The source code is quite readable and understandable:
# -*- coding: utf-8 -*- import android import urllib2 from xml.etree import ElementTree droid = android.Android() droid.vibrate() #      user = droid.dialogGetInput(' ', ' habrahabr.ru').result #     droid.dialogCreateSpinnerProgress("", " ")#         droid.dialogShow() try: feed = urllib2.urlopen('http://habrahabr.ru/api/profile/' + user) #  XML XML = ElementTree.XML(feed.read()) #   XML except: droid.dialogCreateAlert(' ', "   ") #      droid.dialogSetPositiveButtonText('') droid.dialogShow() exit() droid.dialogDismiss() #    if XML[0].text == '404': #        droid.dialogCreateAlert(' ', "   ") #      droid.dialogSetPositiveButtonText('') droid.dialogShow() exit() droid.dialogCreateAlert(' ', XML[1].text) #      droid.dialogSetPositiveButtonText('') droid.dialogShow() 


Parse the source code

The android library contains all the functions for working with the system, such as the Android OS interface, various "phone functions", such as vibration, calls, geolocation, etc.
Creating dialogs is also a very simple process, which resulted in creating 3 windows:
imageimageimage
As well as a couple of windows reporting errors.

Conclusion

Now Python for Android OS is quite usable and suitable for solving small problems. For fans of Python, who are too lazy to learn Java to work with this mobile OS, this is the best option. If this article pleases users, then I'm ready to continue writing about other Python features on SL4A.

Source: https://habr.com/ru/post/122188/


All Articles