예제 #1
0
def run(t):
    while(True):
        # response = requests.get(URL)
        # response.encoding = 'gb2312'
        # text = response.text[1:-1]
        # test = json.loads(text)

        html = urllib2.urlopen(Json_URL)

        context = json.loads(html.read())
        tag = False

        for store in context.keys():
            if store != "updated":
                for model in context[store].keys():
                    # print util.getStore(store)+util.getMode(model)

                    if context[store][model] == True:
                        tag = True
                        print store+''+model
                        print util.getStore(store)+' '+util.getMode(model)
                        webbrowser.open_new_tab(Output_URL)
                        message.send_mail(mail_list,"iphone",util.getStore(store)+' '+util.getMode(model))
        if tag:
            time.sleep(120)
        time.sleep(float(t))
def createListing(episodes, showname): # TODO maybe localize
	listing = []
	for item in episodes:
		status = item[len(item)-1]
		statusstring = ''
		if status == 0:
			statusstring = localize(30301)
		elif status == 1:
			statusstring = localize(30302)
		elif status == 2:
			statusstring = localize(30303)
		if(item[0] == 0):
			episode = localize(30304) + " " + ('%02d' % item[1])
		else:
			episode = "S" + ('%02d' % item[0]) + "E" + ('%02d' % item[1])
		if item[3]:
			airedstring = "(" + item[3] + ")"
		else:
			airedstring = "(" + localize(30305) + ")"
		title = episode + " [" + statusstring + "]" + ": " + unicode(item[2], "utf-8") + " " + airedstring
		mode = util.getMode()
		mode.mode = "episode"
		mode.episode = Episode(int(item[0]), int(item[1]), str(item[2]), str(item[3]))
		listitem = xbmcgui.ListItem(title, statusstring, path="file", thumbnailImage="thumb.png", iconImage="iconimage.png")
		# Add manual search to context menu
		mode2 = ModeClass("manualsearch")
		mode2.show = mode.show
		mode2.episode = Episode(int(item[0]), int(item[1]), str(item[2]), str(item[3]))
		contextmenuitem = (localize(30004),"XBMC.Container.Update(%s)" % (sys.argv[0] + urllib.quote_plus(pickle.dumps(mode2)) + '/'))
		listitem.addContextMenuItems([contextmenuitem])
		listing.append([pickle.dumps(mode), listitem, True])
	return listing
def createMissingEpisodeList():	
	ignoreskippedstring = xbmcplugin.getSetting(thisPlugin, "ignoreskipped")
	ignoreskipped = ignoreskippedstring == 'True'
	mode = util.getMode()
	showid = mode.show.xbmcId
	showname = mode.show.titel
	#check if showid exists in xmldatabase else
	scraperID = database.getScraperId(showid)
	if  scraperID == -1:
		scraperID = util.matchSerie(showname)
		if scraperID == -1:
			return []
		database.addSerie(scraperID)
	#rpdb2.start_embedded_debugger('pw')
	scraper_episodes = scraper.getEpisodeInfo(scraperID)
	# TODO write scraper episodes to disk
	xbmc_episodes = getExistingEpisodes(showid)
	episodes = []
	if ignoreskipped:
		episodes = getNewEpisodes(xbmc_episodes, scraper_episodes)
	else:
		episodes = getMissingEpisodes(xbmc_episodes, scraper_episodes)
	listing = createListing(episodes, showname)
	if not listing:
		header = localize(30001)
		message = localize(30002)
		msg(header,message % showname)
	return listing
예제 #4
0
파일: device.py 프로젝트: gsk727/git
def update():
    """用于添加设备,设备编号是唯一的,或者收到添加。
    """
    deviceInfo = getMode(DeviceMode)
    # 没有添加验证
    for d, _ in deviceMap:
        deviceInfo[d] = request.form.get(d)
    
    devID = deviceInfo["devID"]   # 等级设备的时候设备应该有一个唯一的编号了啊
    if devID is None:
        return "没有设备编号"
        # 下面的操作是非线程安全的
        res = db.device.find_one({"devID": devID})
        if res:
            return "重复编号"

    res = db.device.find_one({"name":deviceInfo["name"]}, {"_id":0})
    
    # 过程太繁琐了
    try:
        h = res.pop("histroy")
        index = h[0] = h[0]%MAX_HISTORY_LEN + 1
    except:
        h = [0, ]
        h.extend([{} for x in xrange(0, MAX_HISTORY_LEN)])
        index = h[0] = h[0] % MAX_HISTORY_LEN + 1

    # histroy=[index, {}, {}, {}]最多 MAX_HISTORY_LEN 个, index记录最前面的一个记录
    h[index] = copy.deepcopy(res)  # 递归问题
    res["history"] = h
    res.update(deviceInfo)
    db.device.save(res)
    return jsonify(message="ok")
예제 #5
0
 def updateProperty(form):
     task = getMode(TaskMode)
     task.clear()
     task.query.update({"number": taskid})
     task.doc.update(form.asDict())
     task.update(keyUpdate = False)
     data.update(form.asDict())
     return True
예제 #6
0
파일: device.py 프로젝트: gsk727/git
def add():
    """用于添加设备,设备编号是唯一的,或者收到添加。
    """
    deviceInfo = getMode(DeviceMode)
    
    # 没有添加验证
    for d, _ in deviceMap:
        deviceInfo[d] = request.form.get(d, "").strip()

    deviceInfo.insert()
    return jsonify(message="ok")
예제 #7
0
def update():
    updateInfo = getMode(AirlineMode)

    for k, _, checkFun in airlineMap:
        updateInfo[k] = request.form.get(k, "").strip() 
        msg = checkFun(**updateInfo)
        if msg != "ok":
           return jsonify(message=msg)

    updateInfo.update()
    return jsonify(message="ok")
예제 #8
0
파일: content.py 프로젝트: gsk727/git
def update():
    """
    数据的更新
    """
    updateInfo = getMode(ContentMode)
    for k, _, in contentMap:
        updateInfo[k] = request.form.get(k, "").strip()
    
    updateInfo.query = {"title":updateInfo.title} 
    updateInfo.update() 
    # db.content.update({"title":updateInfo["title"]}, updateInfo)
    return jsonify(message="ok")
예제 #9
0
def add(base):
    addFrm = TaskAddForm()
    regx = re.compile("^%s$" % (base,), re.IGNORECASE)
    if not db.base.find_one({"number": regx}):
        flash(_(u"不存在的基地"), "error")
    elif addFrm.validate_on_submit():
        tm = getMode(TaskMode)
        tm.doc.update(addFrm.asDict())
        tm.doc.update({"base": base})
        tm.insert()
        flash(_(u"总算成功了啊"), "success")

    return render_template("add.html", addForm = addFrm, addURL = url_for("task.add", base=base))
def addSerie(scraperid):
	mode = util.getMode()
	xbmcid = mode.show.xbmcId
	xbmcName = mode.show.titel
	f = getDatabase("r")
	soup = BeautifulSoup(f.read())
	f.close()
	serie = soup.findAll(scraperid = scraperid)
	if len(serie) == 0 :
		series = soup.find("series")
		tag = Tag(soup, "serie")
		tag.attrs.append(('xbmcid', xbmcid))
		tag.attrs.append(('scraperid', scraperid))
		tag.attrs.append(('xbmcname', xbmcName))
		series.append(tag)
		f = getDatabase("w")
		f.write(soup.prettify())
		f.close()
	elif len(serie) == 1:
		serieTag = serie[0]
		sid = int(serieTag['xbmcid'])
		xName = str(serieTag['xbmcname'])
		if xName != xbmcName or sid != xbmcid:
			#data is inconsistent
			#remove tag
			serieTag.extract()
			f = getDatabase("w")
			f.write(soup.prettify())
			f.close()
			#add new tag
			return addSerie(scraperid)
		else:
			return		#data is consistent no change is needed
	else:
		#more then one match for a serie
		#remove all matching tags
		for item in serie:
			item.extract()
		f = getDatabase("w")
		f.write(soup.prettify())
		f.close()
		#add new tag
		return addSerie(scraperid)
def createShowList():
	json_query = xbmc.executeJSONRPC('{"jsonrpc": "2.0", "method": "VideoLibrary.GetTVShows", "params": {"properties": ["title", "file", "thumbnail", "art"], "sort": { "method": "title" } }, "id": 1}')
	json_query = unicode(json_query, 'utf-8', errors='ignore')
	json_response = simplejson.loads(json_query)
	listing = []
	shows = json_response['result']['tvshows']
	for items in shows:
		mode = util.getMode()
		mode.mode = "tvshow"
		mode.show = TvShow(items["title"], int(items["tvshowid"]))
		title = items['title']
		listitem = xbmcgui.ListItem(title)
		listitem.setIconImage("")
		listitem.setThumbnailImage(items['thumbnail'])
		if database.getScraperId(items["tvshowid"]) != -1:
			mode2 = ModeClass("changetvshow")
			mode2.show = TvShow(items["title"], int(items["tvshowid"]))
			contextmenuitem = (localize(30003),"XBMC.Container.Update(%s)" % (sys.argv[0] + pickle.dumps(mode2) + '/'))
			listitem.addContextMenuItems([contextmenuitem])
		listing.append([pickle.dumps(mode) , listitem, True])
	return listing
def createSearchString():
	#rpdb2.start_embedded_debugger('pw')
	mode = util.getMode()
	showname = mode.show.titel
	season = mode.episode.seasonnr
	episode = mode.episode.episodenr
	title = mode.episode.titel
	firstaired = mode.episode.firstAired
	
	search = ""
	searchseriesname = (xbmcplugin.getSetting(thisPlugin, "searchseriesname") == "true")
	searchepisodename = (xbmcplugin.getSetting(thisPlugin, "searchepisodename") == "true")
	searchseasonnr = (xbmcplugin.getSetting(thisPlugin, "searchseasonnr") == "true")
	searchepisodenr = (xbmcplugin.getSetting(thisPlugin, "searchepisodenr") == "true")
	searchaireddate = (xbmcplugin.getSetting(thisPlugin, "searchaireddate") == "true")
	seasonepisodeformat = xbmcplugin.getSetting(thisPlugin, "seasonepisodeformat")
	if searchseriesname:
		search += showname
	if searchepisodename:
		search += title
	if searchseasonnr and searchepisodenr and seasonepisodeformat != localize(32005):
		if seasonepisodeformat == localize(32001):
			search += " S" + ('%02d' % season) + "E" + ('%02d' % episode)
		elif seasonepisodeformat == localize(32002):
			search += " S" + str(season) + "E" + str(episode)
		elif seasonepisodeformat == localize(32003):
			search +=('%02d' % season) + "x" + ('%02d' % episode)
		elif seasonepisodeformat == localize(32004):
			search += str(season) + "x" + str(episode)
	else:
		if searchseasonnr:
			search += "Season " + season
		if searchepisodenr:
			search += "Episode " + episode
	if searchaireddate:
		search += firstaired
	return search
# @return NONE
def sendToXbmc(listing):
	global thisPlugin
	if not listing:
		return
	for item in listing:
		listItem = item[1]
		item[0] = urllib.quote_plus(item[0])
		xbmcplugin.addDirectoryItem(thisPlugin,sys.argv[0] + item[0] + "/",listItem, isFolder=item[2], totalItems=len(listing) -1)
	xbmcplugin.endOfDirectory(thisPlugin)
	

if not database.databaseExists():
	database.initDatabase()

mode = util.getMode()
if(mode.mode == "start"):
	sendToXbmc(startMode.createShowList())
else:
	if(mode.mode == "tvshow"):
#		rpdb2.start_embedded_debugger('pw')
		sendToXbmc(tvshowMode.createMissingEpisodeList())
	elif(mode.mode == "episode"):
		#rpdb2.start_embedded_debugger('pw')
		sendToXbmc(searchMode.search(False))
	elif(mode.mode == "changetvshow"):
		scraperID = util.matchSerie(util.getKeyboardString(mode.show.titel,localize(30005)));
		if scraperID != -1:
			database.addSerie(scraperID)
	elif(mode.mode == "manualsearch"):
		sendToXbmc(searchMode.search(True))