Editing Hildon Event Feed

Warning: You are not logged in. Your IP address will be recorded in this page's edit history.
The edit can be undone. Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision Your text
Line 142: Line 142:
  #!/usr/bin/env python
  #!/usr/bin/env python
   
   
-
from __future__ import with_statement
 
  import urllib2
  import urllib2
  import simplejson
  import simplejson
  import dbus
  import dbus
  import datetime
  import datetime
 +
import io
  import sys
  import sys
   
   
  LAST_RUN_DATE_TIME_FILE = '/home/user/Event Feed/examples/YouTube/last_run.txt' # File to read/write serialized date/time when script was last run.
  LAST_RUN_DATE_TIME_FILE = '/home/user/Event Feed/examples/YouTube/last_run.txt' # File to read/write serialized date/time when script was last run.
-
  SCRIPT_FILE = '/home/user/Event\ Feed/examples/YouTube/get_youtube_videos' # Path to the script.
+
  SCRIPT_FILE = '/home/user/Event Feed/examples/YouTube/get_youtube_videos' # Path to the script.
   
   
  def get_youtube_videos(query):
  def get_youtube_videos(query):
-
  """ Retrieve YouTube videos and populate the Hildon Event Feed
+
  """Retrieve YouTube videos and populate the Hildon Event Feed
 
 
-
    Usage: get_youtube_videos [query]
+
  Usage: get_youtube_videos [query]
         """
         """
      
      
Line 164: Line 164:
  source_name = 'youtube_example' # Identifies the source of the events. Must be unique to the source.
  source_name = 'youtube_example' # Identifies the source of the events. Must be unique to the source.
  source_display_name = 'YouTube' # Display name for the source in the event feed UI.
  source_display_name = 'YouTube' # Display name for the source in the event feed UI.
-
  icon = '/home/user/Event Feed/examples/YouTube/youtube_icon.png' # Icon to be displayed in the event feed UI.
+
  icon = 'https://lh4.googleusercontent.com/-4QDxins1Vgw/AAAAAAAAAAI/AAAAAAAAGYw/sM3FJY9Asl4/s250-c-k/photo.jpg' # Icon to be displayed in the event feed UI.
  action = 'dbus:system com.nokia.osso_browser /com/nokia/osso_browser/request com.nokia.osso_browser load_url' # This will be called when the user taps on an item in the event feed. In this example, the video url is opened in the browser.
  action = 'dbus:system com.nokia.osso_browser /com/nokia/osso_browser/request com.nokia.osso_browser load_url' # This will be called when the user taps on an item in the event feed. In this example, the video url is opened in the browser.
  refresh_action = 'exec python %s %s' % (SCRIPT_FILE, query) # This will be called when the user presses the 'Refresh' button in the event feed UI.
  refresh_action = 'exec python %s %s' % (SCRIPT_FILE, query) # This will be called when the user presses the 'Refresh' button in the event feed UI.
Line 216: Line 216:
 
 
  try:
  try:
-
  with open(LAST_RUN_DATE_TIME_FILE, 'r') as file:
+
  with io.open(LAST_RUN_DATE_TIME_FILE, 'r') as file:
  date_time_string = file.read()
  date_time_string = file.read()
  file.close()
  file.close()
Line 235: Line 235:
   
   
  try:
  try:
-
  with open(LAST_RUN_DATE_TIME_FILE, 'w') as file:
+
  with io.open(LAST_RUN_DATE_TIME_FILE, 'w') as file:
  file.write(unicode(date_time_string))
  file.write(unicode(date_time_string))
  file.close()
  file.close()
Line 247: Line 247:
  print 'Usage: get_youtube_videos [query]'
  print 'Usage: get_youtube_videos [query]'
   
   
-
 
+
'''Example Python script to retrieve an RSS feed (default is latest TMO threads) and post new items to the event feed.
'''Example Python script to retrieve an RSS feed (default is latest TMO threads) and post new items to the event feed.
  #!/usr/bin/env python
  #!/usr/bin/env python
   
   
-
from __future__ import with_statement
 
  import xml.dom.minidom as DOM
  import xml.dom.minidom as DOM
  import urllib2
  import urllib2
Line 258: Line 257:
  import re
  import re
  import datetime
  import datetime
 +
import io
  import sys
  import sys
   
   
  LAST_RUN_DATE_TIME_FILE = '/home/user/Event Feed/examples/RSS Feed/last_run.txt' # File to read/write serialized date/time when script was last run.
  LAST_RUN_DATE_TIME_FILE = '/home/user/Event Feed/examples/RSS Feed/last_run.txt' # File to read/write serialized date/time when script was last run.
-
  SCRIPT_FILE = '/home/user/Event\ Feed/examples/RSS\ Feed/get_rss_feed' # Path to the script.
+
  SCRIPT_FILE = '/home/user/Event Feed/examples/RSS Feed/get_rss_feed' # Path to the script.
   
   
  def get_rss_feed(feed = 'http://talk.maemo.org/external.php?type=RSS2'):
  def get_rss_feed(feed = 'http://talk.maemo.org/external.php?type=RSS2'):
Line 270: Line 270:
  icon = '/usr/share/icons/hicolor/64x64/hildon/general_rss.png' # Icon for the events in the UI
  icon = '/usr/share/icons/hicolor/64x64/hildon/general_rss.png' # Icon for the events in the UI
  action = 'dbus:system com.nokia.osso_browser /com/nokia/osso_browser/request com.nokia.osso_browser load_url' # This will be called when the user taps on an item in the event feed. In this example, the link is opened in the browser.
  action = 'dbus:system com.nokia.osso_browser /com/nokia/osso_browser/request com.nokia.osso_browser load_url' # This will be called when the user taps on an item in the event feed. In this example, the link is opened in the browser.
-
  refresh_action = 'exec python %s %s' % (SCRIPT_FILE, feed) # When this refresh action is added, the script will be called again (with same feed) when the 'Refresh' button is pressed in the event feed UI.
+
  refresh_action = 'exec python %s %s ' % (SCRIPT_FILE, feed) # When this refresh action is added, the script will be called again (with same feed) when the 'Refresh' button is pressed in the event feed UI.
 
 
  bus = dbus.SessionBus()
  bus = dbus.SessionBus()
-
  iface = dbus.Interface(bus.get_object('com.maemo.eventFeed', '/'), 'com.maemo.eventFeed') # Get the event feed dbus object
+
  iface = dbus.Interface(bus.get_object("com.maemo.eventFeed", "/"), "com.maemo.eventFeed") # Get the event feed dbus object
  iface.addRefreshAction(source_name, refresh_action) # Add the refresh action to the event feed.
  iface.addRefreshAction(source_name, refresh_action) # Add the refresh action to the event feed.
 
 
-
  last_run = script_last_run() # Time when script was last run. Will be used to check against the date/time of each item in the feed.
+
  last_run = script_last_run() # Time when script was last run. Will be used to check against the date of each item in the feed.
 
 
  rss = urllib2.urlopen(feed).read()
  rss = urllib2.urlopen(feed).read()
Line 288: Line 288:
  footer = ''
  footer = ''
  timestamp = ''
  timestamp = ''
 +
action = ''
 
 
  for item in items:
  for item in items:
Line 305: Line 306:
  elif nodeName == 'content:encoded':
  elif nodeName == 'content:encoded':
  images = get_images(node.firstChild.data)
  images = get_images(node.firstChild.data)
-
+
  try:
  try:
  item_date_time = datetime.datetime.strptime(timestamp[0:timestamp.rfind(' ')], '%a, %d %b %Y %H:%M:%S')
  item_date_time = datetime.datetime.strptime(timestamp[0:timestamp.rfind(' ')], '%a, %d %b %Y %H:%M:%S')
Line 311: Line 312:
  print 'Cannot parse item date/time. Using default'
  print 'Cannot parse item date/time. Using default'
  item_date_time = datetime.datetime.min
  item_date_time = datetime.datetime.min
-
+
  if item_date_time > last_run:
  if item_date_time > last_run:
  print iface.addEvent(source_name, display_name, icon, title, body, images, footer, timestamp, '%s %s' % (action, link)) # If item is new, add an event to the event feed and print the reply.
  print iface.addEvent(source_name, display_name, icon, title, body, images, footer, timestamp, '%s %s' % (action, link)) # If item is new, add an event to the event feed and print the reply.
Line 324: Line 325:
 
 
  try:
  try:
-
  with open(LAST_RUN_DATE_TIME_FILE, 'r') as file:
+
  with io.open(LAST_RUN_DATE_TIME_FILE, 'r') as file:
  date_time_string = file.read()
  date_time_string = file.read()
  file.close()
  file.close()
Line 343: Line 344:
   
   
  try:
  try:
-
  with open(LAST_RUN_DATE_TIME_FILE, 'w') as file:
+
  with io.open(LAST_RUN_DATE_TIME_FILE, 'w') as file:
  file.write(unicode(date_time_string))
  file.write(unicode(date_time_string))
  file.close()
  file.close()

Learn more about Contributing to the wiki.


Please note that all contributions to maemo.org wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see maemo.org wiki:Copyrights for details). Do not submit copyrighted work without permission!


Cancel | Editing help (opens in new window)