Reputation: 37
I try to use an ini file to configure the resolution to use in my script and need help to know how to do this.
"Fontion script":
#RECUP QUALITE FHD
import re, os
def FHD(RFHD):
mykey = open("/home/gaaara/adn/tmp/ajax.json", "r")
for text in mykey:
match = re.search('"FHD":"(.+?).mp4', text)
if match:
s = 'http://www.website.fr:1935/' + match.group(1) + '.mp4?audioindex=0.smil'
return s
In fact it has 2 other similar functions in the file HD
and SD
which are the others function of resolution. How do I programmatically select the right function?
Edit
import ConfigParser
import sys
sys.path.append('files/')
from xrez import FHD
from xrez import HD
from xrez import SD
#variables
x1080 = FHD('RFHD')
x720 = HD('RHD')
x480 = SD('RSD')
#fin
config = ConfigParser.ConfigParser()
config.read('config.ini')
try:
val = config.get('resolution', 'Write the resolution wish', 'x1080' , 'x720' , 'x480' )
except:
sys.exit(1)
print val
Upvotes: 0
Views: 655
Reputation: 6775
some ini file like that:
[section1]
var1=value1
Would be read by that:
import ConfigParser
config = ConfigParser.ConfigParser()
config.read('conf.ini')
try:
val = config.get('section1', 'var1')
except:
sys.exit(1)
print val
Upvotes: 1
Reputation: 249153
You can use the Python ConfigParser library. This will read your INI file and give you the parameters you need (e.g. resolution), which you can then use in your JSON downloading code.
Upvotes: 2