upload function now included into record script.
This commit is contained in:
parent
dc0ea0a532
commit
76b1e3b7f7
1 changed files with 14 additions and 26 deletions
|
@ -4,10 +4,14 @@ import logging
|
||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import datetime
|
import datetime
|
||||||
|
import os
|
||||||
|
|
||||||
from eci import *
|
from eci import *
|
||||||
from configobj import ConfigObj
|
from configobj import ConfigObj
|
||||||
import subprocess
|
|
||||||
|
from poster.encode import multipart_encode
|
||||||
|
from poster.streaminghttp import register_openers
|
||||||
|
import urllib2
|
||||||
|
|
||||||
# loading config file
|
# loading config file
|
||||||
try:
|
try:
|
||||||
|
@ -73,11 +77,6 @@ def check_record():
|
||||||
start_time = sorted_show_keys[0]
|
start_time = sorted_show_keys[0]
|
||||||
next_show = getDateTimeObj(start_time)
|
next_show = getDateTimeObj(start_time)
|
||||||
|
|
||||||
#print tnow, next_show
|
|
||||||
|
|
||||||
#tnow = getDateTimeObj("2011-03-04 16:00:00")
|
|
||||||
#next_show = getDateTimeObj("2011-03-04 16:00:01")
|
|
||||||
|
|
||||||
delta = next_show - tnow
|
delta = next_show - tnow
|
||||||
|
|
||||||
if delta <= datetime.timedelta(seconds=60):
|
if delta <= datetime.timedelta(seconds=60):
|
||||||
|
@ -85,20 +84,15 @@ def check_record():
|
||||||
|
|
||||||
show_length = shows_to_record[start_time]
|
show_length = shows_to_record[start_time]
|
||||||
filepath = record_show(show_length.seconds, start_time)
|
filepath = record_show(show_length.seconds, start_time)
|
||||||
#filepath = record_show(10, "2011-03-04 16:00:00")
|
upload_file(filepath)
|
||||||
|
|
||||||
command = "%s -c %s" %("../../utils/airtime-import", filepath)
|
|
||||||
subprocess.call([command],shell=True)
|
|
||||||
|
|
||||||
|
|
||||||
def get_shows():
|
def get_shows():
|
||||||
|
|
||||||
url = config["base_url"] + config["show_schedule_url"]
|
url = config["base_url"] + config["show_schedule_url"]
|
||||||
#url = url.replace("%%from%%", "2011-03-13 20:00:00")
|
|
||||||
#url = url.replace("%%to%%", "2011-04-17 21:00:00")
|
|
||||||
|
|
||||||
response = urllib.urlopen(url)
|
response = urllib.urlopen(url)
|
||||||
data = response.read()
|
data = response.read()
|
||||||
|
|
||||||
response_json = json.loads(data)
|
response_json = json.loads(data)
|
||||||
shows = response_json[u'shows']
|
shows = response_json[u'shows']
|
||||||
print shows
|
print shows
|
||||||
|
@ -107,22 +101,16 @@ def get_shows():
|
||||||
process_shows(shows)
|
process_shows(shows)
|
||||||
check_record()
|
check_record()
|
||||||
|
|
||||||
def upload_file():
|
def upload_file(filepath):
|
||||||
|
|
||||||
from poster.encode import multipart_encode
|
filename = os.path.split(filepath)[1]
|
||||||
from poster.streaminghttp import register_openers
|
|
||||||
import urllib2
|
|
||||||
|
|
||||||
# Register the streaming http handlers with urllib2
|
# Register the streaming http handlers with urllib2
|
||||||
register_openers()
|
register_openers()
|
||||||
|
|
||||||
# Start the multipart/form-data encoding of the file "DSC0001.jpg"
|
|
||||||
# "image1" is the name of the parameter, which is normally set
|
|
||||||
# via the "name" parameter of the HTML <input> tag.
|
|
||||||
|
|
||||||
# headers contains the necessary Content-Type and Content-Length
|
# headers contains the necessary Content-Type and Content-Length
|
||||||
# datagen is a generator object that yields the encoded parameters
|
# datagen is a generator object that yields the encoded parameters
|
||||||
datagen, headers = multipart_encode({"file": open("/home/naomi/Music/testoutput.mp3", "rb"), 'name': 'crazy.mp3'})
|
datagen, headers = multipart_encode({"file": open(filepath, "rb"), 'name': filename})
|
||||||
|
|
||||||
url = config["base_url"] + config["upload_file_url"]
|
url = config["base_url"] + config["upload_file_url"]
|
||||||
|
|
||||||
|
@ -133,11 +121,11 @@ def upload_file():
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
||||||
# while True:
|
while True:
|
||||||
# get_shows()
|
get_shows()
|
||||||
# time.sleep(30)
|
time.sleep(30)
|
||||||
|
|
||||||
upload_file()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue