Showing posts with label Python. Show all posts
Showing posts with label Python. Show all posts

Thursday, September 18, 2014

Android Development using Python in Linux (Ubuntu)

There are a few steps:
Prerequisite:
$ sudo apt-get install python-setuptools python-pygame python-opengl python-gst0.10 python-enchant gstreamer0.10-plugins-good cython python-dev build-essential libgl1-mesa-dev libgles2-mesa-dev

$ python
>>> import pkg_resources
>>> print pkg_resources.resource_filename('kivy', '../share/kivy-examples')
# Copy the address
>>> exit()

$ ln -s address

# Check the kivy examples
$ cd kivy-examples
$ cd demo/touchtracer
$ python main.py

Build the distribution
./distribute.sh -m "kivy"
The file "distribute.sh" can be found at /home/bz/python-for-android


Friday, May 17, 2013

Python - Part 2 Playing with Twitter API


Install Python if never installed before:
bowen@bowen:~$ sudo apt-get install python-pip python-dev build-essential

bowen@bowen:~$ sudo pip install python-twitter

Run Python
bowen@bowen:~$ python
>>> import twitter
>>> api = twitter.Api()
>>> api = twitter.Api(consumer_key='consumer_key',consumer_secret='consumer_secret', access_token_key='access_token', access_token_secret='access_token_secret')

#Replace all ' ' into your own key.

Some functionality that we can play with:
>>> users=api.GetFriends()
>>> print [u.name for u in users]

>>> statuses = api.GetUserTimeline()
>>> print [s.user.name for s in statuses]

>>> status = api.PostUpdate('Test Twitter message via Python')


And acquiring more information even without third party package:

import urllib
import simplejson

def searchTweets(query):
 search = urllib.urlopen("http://search.twitter.com/search.json?q="+query)
 dict = simplejson.loads(search.read())
 for result in dict["results"]: # result is a list of dictionaries
  print "*",result["text"],"\n"

# we will search tweets about "gator game" 
searchTweets("gator+game&rpp=50") # &rpp here is to offer arbitrary results that is more than 15.

Just list a few results here:
* RT @colebutler787: Great game tonight guys! @eLEMONator17 @BrandonMoz89 @JonathanW37 @JustenKinder @sirtwinksalots @khumphries734 @gator_dav15 @TheDaveMaster0

* RT @colebutler787: Great game tonight guys! @eLEMONator17 @BrandonMoz89 @JonathanW37 @JustenKinder @sirtwinksalots @khumphries734 @gator_dav15 @TheDaveMaster0

* @BrandtSnedeker at a Florida Gator football game, duh

* RT @colebutler787: Great game tonight guys! @eLEMONator17 @BrandonMoz89 @JonathanW37 @JustenKinder @sirtwinksalots @khumphries734 @gator_dav15 @TheDaveMaster0

* RT @colebutler787: Great game tonight guys! @eLEMONator17 @BrandonMoz89 @JonathanW37 @JustenKinder @sirtwinksalots @khumphries734 @gator_dav15 @TheDaveMaster0

* RT @colebutler787: Great game tonight guys! @eLEMONator17 @BrandonMoz89 @JonathanW37 @JustenKinder @sirtwinksalots @khumphries734 @gator_dav15 @TheDaveMaster0

* RT @CHCAWarriors: Awesome crowd at tonight's game.
 Final CHCA 6 St. Luke's 6
Good jobs guys, time to hit the weight room and get ready for the fall.

* Great game tonight guys! @eLEMONator17 @BrandonMoz89 @JonathanW37 @JustenKinder @sirtwinksalots @khumphries734 @gator_dav15 @TheDaveMaster0

* I liked a @YouTube video from @iheartmakeup92 http://t.co/Tflm5sFnt4 Get Ready With Me│GATOR GAME STYLE

* You can't have a conscience in the pimp game. #gator

* RT @Jhalapio33: Had a lot of tackles today with two assist tackles and 2 sacks ! Blessed with a good game !

* @0hMelissaRegan yay Zoey!!!!! Man I might have to go to a Gator game to see her cheer... Eeeeee.... We will have to make it the FSU/UF game

* If Gametracker is tracking the UGA-UF game in real time, then it took Gator reliever Parker Danciu 12 minutes to throw to one batter.

* I can't belive that was my last game as a gator, I'm going to miss it so much 😭

* RT @DoubleO_55: Pumped for the the blue and gold game.🏈 #blueteamswag @AlRoberts16 @J_Flinno @gator_68 @T_sully42 @JaredEidson6 @CadenRicketts


Monday, May 13, 2013

Python - Part 1

Install Python and run the Python Shell.

The command line offers the functionality that you can directly input the arithmetic calculations and string inputs. For example, type "3<4" and get the "True" results.
Another example, type
>>> three = str('3')
The results will be '3' if you type three

There are also other special arithmetic calculations apart from normal add, subtract, multiplication, and division such as // (integer division), not (as opposed to), and (both statement has to be in order to get "True"), or (either one of the statement is true to make the result "True"), etc.

Now consider
>>> num = int(input('give me a number'))
if you input number like 500, the num can be compared as a number.
>>> num2 = 400
>>> num > num2
True