OHO's Blog

My 2 cents about everything!

Pythonista: An Impressive App in Apple App Store

Discover an app that is a good start for Python beginners

I was looking at the App Store for quick Python learning apps or some kind of python quick hints apps. I felt down on Pythonista and realised later that the developer was the same as the one who made NewsRack (my first and favorite RSS reader app).

This app is just enormous and one of the most impressive one I could find on the App Store.

There are lots of smalls implementations details. The type of details that make a great app being a great app! If you are a developper, I’m sure you will agree with me and categorized this one as a reference.

Ok, it’s a paid app, but even if after several months (yes, this app is there for a while now) I don’t use it much, I do not regret my payment that really worth it.

This is without talking about all Python dev and library packaging that the all app is about. It’s impressive to see that you really can developp from within the app, with color synthax and completion code!

You can learn more about the app on developer website.

Sample test code: geting app store review note

I’m currently writing this blog post as today I was looking for the piece of Python code I wrote few months ago while I was trying and playing with Pythonista. And as the best way to find back usefull info, code or trick you migh want to share is to do a blog post, here it is!

This code (shown bellow) is parsing App Store reviews from Apple official RSS feed.

You can run this piece of code directly from Pythonista app and get reviews for any given App ID. A fun trick is also to use Pythonista URL Scheme and save in native note application clickable links that get reviews for a selection of App IDs.

Ex: pythonista://_appreviews?action=run&args=528579881

This sample code can be retreive and share through GitHub Gist.

Here is what it looks like:

(_appreviews.py) download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
# Pythonista script
# Script name: getreviews.py
# Author: Olivier HO-A-CHUCK
# License (OHO Ware): free to use modify, alter, re-use for commercial use or not! :)
# Date: Nov. 15th 2012 
# Usage: pythonista://_appreviews?action=run&args=<appID>
# exemple: pythonista://_appreviews?action=run&args=308816822

import json
import urllib2
import re
import console
import clipboard
import sys

if len(sys.argv) == 1:
  appID = '530524743' #overblog
else:
  appID = sys.argv[1]

url = 'http://itunes.apple.com/fr/rss/customerreviews/id=' + appID + '/sortby=mostrecent/json'

console.clear()
response = urllib2.urlopen(url)
content = response.read()
data = json.loads(content.decode("utf8"))
text    = ''
print("Application ID: " + appID)
text += "Application ID: " + appID + "\n"
lastUpdate = data['feed']['updated']['label']
print("last comments update: " + lastUpdate)
text += "last comments update: " + lastUpdate + "\n\n"
lastPage = data['feed']['link'][3]['attributes']['href']
#print(lastPage)
nbPages = int(re.findall(r".*page=(\d*)/.*", lastPage)[0])
print("Theoritical number of pages: " + str(nbPages))
maxPages = nbPages
maxPages = maxPages if nbPages < 10 else 10
print("Using " + str(maxPages) + " pages ...\n\n");

i = 0
page = 1
while page < maxPages+1:
#while page < int(nbPages)+1:
  urlPos = re.sub("customerreviews","customerreviews/page="+str(page),url)
  response = urllib2.urlopen(urlPos)
  content = response.read()
  data = json.loads(content.decode("utf8"))
  if len(data['feed']['entry']) == 11:  # if script does not work anymore, check if this is still true!
      page += 1
      continue
  for entryIndex in data['feed']['entry']:
      if i == 0:
          i = 1
          continue
      #print(str(i) + ": " + entryIndex['title']['label'])
      version = entryIndex['im:version']['label']
      rating = entryIndex['im:rating']['label']
      title = entryIndex['title']['label']
      author = entryIndex['author']['name']['label']
      content = entryIndex['content']['label']
      print(str(page) +"."+ str(i) + ": " + "("+ version +") "+ rating + "* [" + author + "] " + title)
      text += str(page) +"."+ str(i) + ": " + "("+ version +") "+ rating + "* [" + author + "] " + title + "\n"
      print(content+"\n--")
      text += content+"\n--\n"
      i += 1
  page += 1
  i = 0
  
clipboard.set(text)

Note: if you want to test this code from a desktop, remove any call to console or clipboard references (including imports). Please note that country store is hard coded.

Comments