File: plumi_generator.py

package info (click to toggle)
freej 0.10git20100110-1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 32,080 kB
  • ctags: 22,705
  • sloc: cpp: 156,254; ansic: 25,531; sh: 13,538; perl: 4,624; makefile: 3,278; python: 2,889; objc: 1,284; asm: 1,125; ruby: 126
file content (53 lines) | stat: -rw-r--r-- 1,586 bytes parent folder | 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
#/usr/bin/python2.5
# andy@engagemedia.org
#generate a FreeJ javascript file, using a RSS2 feed

# from elementtree import ElementTree as et
from xml.etree import ElementTree as et
from Cheetah.Template import Template
import urllib
import os
import shutil

RSS_FILE="http://www.engagemedia.org/featured-videos/RSS2"
JAVASCRIPT_TEMPLATE="plumi_template.js"
JAVASCRIPT_FILE="plumi.js"

#download latest RSS2 
print "fetching %s " % RSS_FILE
feed = urllib.urlopen(RSS_FILE)
print "parsing %s " % RSS_FILE
parsed_feed = et.parse(feed)

#setup the parameters from channel
print "making js file %s " % JAVASCRIPT_FILE
data_map = {}

#download image, and remember path
image_url = parsed_feed.find('channel').find('image').find('url').text
#get the image
print "fetching image logo %s " % image_url
downloaded_image=urllib.urlretrieve(image_url)
#save it somewhere sensible.
image_name=os.path.basename(image_url)
shutil.copyfile(downloaded_image[0],image_name)
#the abs file path
image_file_path=os.path.abspath(image_name)

data_map['image_file_path'] = image_file_path


data_map['channel_title'] = parsed_feed.find('channel').find('title').text
data_map['videos'] = []

for video_elem in parsed_feed.getiterator('enclosure'):
    video_to_play = video_elem.get('url')
    js_var_name = "video_%s" % (len(data_map['videos']))
    video_dict = {'url':video_to_play, 'js_var_name':js_var_name}
    data_map['videos'].append(video_dict)

#write the new javascript file.
t = Template(file=JAVASCRIPT_TEMPLATE, searchList=[data_map])
f=open(JAVASCRIPT_FILE, 'w')
f.write(t.respond())
f.close()