本文整理汇总了Python中firebase.Firebase.update方法的典型用法代码示例。如果您正苦于以下问题:Python Firebase.update方法的具体用法?Python Firebase.update怎么用?Python Firebase.update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类firebase.Firebase
的用法示例。
在下文中一共展示了Firebase.update方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _process_pages
# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import update [as 别名]
def _process_pages(self, spider):
host = spider.get_origin_host()
fire = Firebase('%s/pages/%s' % (self.fire_host, host))
origin_hash = url_hash(host)
cursor = self.db.cursor()
query = """
SELECT content_item_id
, content_node_id
, object_type
, lint_critical
, lint_error
, lint_warn
, lint_info
, lint_results
FROM page
WHERE request_method = 'GET'
AND external = 0
AND object_type IS NOT NULL
AND content_item_id IS NOT NULL
ORDER BY lint_critical DESC, lint_error DESC, lint_warn DESC
LIMIT 20
"""
cursor.execute(query)
rows = cursor.fetchall()
res = {}
for row in rows:
res[row.pop('content_item_id')] = row
fire.update(res)
示例2: get_next
# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import update [as 别名]
def get_next(self):
name_to_id = {}
songs = Firebase(FIREBASE_URL + "songs").get()
vo_ids = []
bg_ids = []
for song_id in songs:
song = songs[song_id]
name_to_id[song['song_name'].lower().replace(" ", "")] = song_id
if song["file_type"] == "instrumental":
bg_ids += [song["id"]]
else:
vo_ids += [song["id"]]
vo_id = vo_ids[int(len(vo_ids) * random.random())]
bg_id = bg_ids[int(len(bg_ids) * random.random())]
next_song = Firebase(FIREBASE_URL + "next_song/")
song_name = next_song.get()['song_name']
if next_song.get()['must_play'] and song_name in name_to_id:
if next_song.get()['song_type'] == 'vocal':
vo_id = name_to_id[song_name]
else:
bg_id = name_to_id[song_name]
next_song.update({'must_play':0, 'song_name':-1})
vo_clip = self.slice_song(vo_id)
bg_clip = self.slice_song(bg_id)
return (vo_clip, bg_clip)
示例3: runForTerm
# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import update [as 别名]
def runForTerm(term, current_time):
last_year = (datetime.datetime.now() - timedelta(days=550))
twitter_counts_to_save = {}
while last_year.strftime('%Y-%m-%d') < current_time:
print(last_year.strftime('%Y-%m-%d'))
while True:
try:
r = requests.get("https://cdeservice.mybluemix.net:443/api/v1/messages/count?q=" + term + "%20posted%3A" + last_year.strftime('%Y-%m-%d') + "%2C" + last_year.strftime('%Y-%m-%d'), auth=('667dedc9-0e40-4860-abe9-55011697cd3d', 'Pxl3qyvFAH'))
parsed_json = json.loads(r.content)
if parsed_json == None:
last_year = last_year + timedelta(days=1)
continue
twitter_counts_to_save[last_year.strftime('%Y-%m-%d')] = long(parsed_json['search']['results'])
last_year = last_year + timedelta(days=1)
break
except:
print("Download Error")
f = Firebase('https://sv2.firebaseio.com/tweets/' + term)
while True:
try:
f.update(twitter_counts_to_save)
break
except:
print ("Upload error...trying again!")
示例4: _process_overall
# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import update [as 别名]
def _process_overall(self, spider):
host = spider.get_origin_host()
fire = Firebase('%s/reports/%s/%s' % (self.fire_host, host,
datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S')))
origin_hash = url_hash(host)
cursor = self.db.cursor()
query = """
SELECT COUNT(1) AS pages
, AVG(p.response_time) AS avg_response_time
, AVG(p.response_time + al.total_response_time) AS avg_total_response_time
, AVG(LENGTH(p.body)) AS avg_page_size
, AVG(LENGTH(p.body) + al.total_size) AS avg_total_page_size
, SUM(p.lint_critical) AS total_lint_critical
, SUM(p.lint_error) AS total_lint_error
, SUM(p.lint_warn) AS total_lint_warn
, SUM(p.lint_info) AS total_lint_info
, AVG(al.internal_assets) AS avg_internal_assets
, AVG(al.external_assets) AS avg_external_assets
, AVG(al.image_assets) AS avg_image_assets
, AVG(al.script_assets) AS avg_script_assets
, AVG(al.total_size) AS avg_asset_weight
FROM page p
, (SELECT from_url_hash AS url_hash
, SUM(response_time) AS total_response_time
, AVG(response_time) AS avg_response_time
, SUM(size) AS total_size
, AVG(size) AS avg_size
, SUM(IF(external=1,0,1)) AS internal_assets
, SUM(IF(external=1,1,0)) AS external_assets
, SUM(IF(asset_type='image',1,0)) AS image_assets
, SUM(IF(asset_type='script',1,0)) AS script_assets
, SUM(IF(asset_type='stylesheet',1,0)) AS style_assets
FROM links l
LEFT JOIN asset a ON l.to_url_hash = a.url_hash
GROUP BY l.from_url_hash) al
WHERE p.request_method = 'GET'
AND p.url_hash = al.url_hash
AND p.origin_hash = %s
"""
cursor.execute(query, [origin_hash])
res = cursor.fetchone()
for k, v in res.iteritems():
if isinstance(v, decimal.Decimal):
res[k] = float(v)
fire.update(res)
示例5: run
# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import update [as 别名]
def run(self):
while True:
start_time = time.time()
cur_speed = Firebase(FIREBASE_URL + "cur_speed/")
bpm = cur_speed.get()['bpm']
dbpm = cur_speed.get()['dbpm']
cur_speed.update({'bpm':bpm+dbpm, 'dbpm':0})
(vo, bg) = self.get_next();
mashup = self.render_next(vo, bg, bpm, dbpm);
self.schedule(mashup)
time.sleep(max(MIX_DURATION - CROSSFADE_TIME - int(time.time() - start_time), 0))
示例6: consider_suggestions
# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import update [as 别名]
def consider_suggestions(self):
body = self.bodyData.split(" ")
next_song = Firebase(FIREBASE_URL + 'next_song/')
if len(body) == 2 and body[0].lower() == 'vocal':
print "NEW VOCALS YEAH"
next_song.update({'must_play':1, 'song_name': body[1].lower(), 'song_type': 'vocal'})
return
elif len(body) == 2 and body[0].lower() == 'instrumental':
next_song.update({'must_play':1, 'song_name': body[1].lower(), 'song_type': 'instrumental'})
return
res = Firebase("https://blazing-fire-4446.firebaseio.com/songs/" + self.bodyData + "/").get()
#print res
if not res:
curFB = Firebase("https://blazing-fire-4446.firebaseio.com/songs/")
curFB.push({'RNG':1, 'file_name':"testFN", 'file_type':"instrumental", 'id':self.bodyData, 'song_name':"testFN", 'start_time':30})
else:
curRNG = Firebase("https://blazing-fire-4446.firebaseio.com/songs/" + self.bodyData + "/RNG/").get()
print curRNG
curRNG = curRNG + 1
print curRNG
rngREF = Firebase("https://blazing-fire-4446.firebaseio.com/songs/" + self.bodyData + "/")
rngREF.update({"RNG": curRNG})
示例7: runStockAlgorithms
# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import update [as 别名]
#.........这里部分代码省略.........
#less than Trend
algoString = ALGO + ":" + str(LOOK_DAYS) + ":" + inner_term + ":" + outer_term + ":World_Stock_Algorithm_79:_" + price
closedLedger = {}
openLedger = {}
simpleLedger = {}
stockStrategy1T(outer_trading_difference, inner_trading_difference, firstTradingDay, thisPriceDictionary, closedLedger, openLedger, algoString, simpleLedger, fiveLedger, tenLedger, fifteenLedger, thirtyLedger, sixtyLedger)
simpleUpdate[algoString] = simpleLedger
#lazy
algoString = ALGO + ":" + str(LOOK_DAYS) + ":" + inner_term + ":" + outer_term + ":World_Stock_Algorithm_80:_" + price
closedLedger = {}
openLedger = {}
simpleLedger = {}
stockStrategy1L(outer_trading_difference, inner_trading_difference, firstTradingDay, thisPriceDictionary, closedLedger, openLedger, algoString, simpleLedger, fiveLedger, tenLedger, fifteenLedger, thirtyLedger, sixtyLedger)
simpleUpdate[algoString] = simpleLedger
fiveLedgerToUpload = {}
for algoName in sorted(fiveLedger, key=fiveLedger.get, reverse=True)[:20]:
tempDic = {}
for day in sorted(simpleUpdate[algoName], reverse=True)[:6]:
tempDic[day] = simpleUpdate[algoName][day]
fiveLedgerToUpload[algoName] = tempDic
print("Uploading " + price)
while True:
try:
ledger = Firebase("https://seagle.firebaseIO.com/" + price + "/five")
ledger.update(fiveLedgerToUpload)
break
except:
print ("Upload error...trying again!")
tenLedgerToUpload = {}
for algoName in sorted(tenLedger, key=tenLedger.get, reverse=True)[:20]:
tempDic = {}
for day in sorted(simpleUpdate[algoName], reverse=True)[:11]:
tempDic[day] = simpleUpdate[algoName][day]
tenLedgerToUpload[algoName] = tempDic
print("Uploading " + price)
while True:
try:
ledger = Firebase("https://seagle.firebaseIO.com/" + price + "/ten")
ledger.update(tenLedgerToUpload)
break
except:
print ("Upload error...trying again!")
fifteenLedgerToUpload = {}
for algoName in sorted(fifteenLedger, key=fifteenLedger.get, reverse=True)[:20]:
tempDic = {}
for day in sorted(simpleUpdate[algoName], reverse=True)[:16]:
tempDic[day] = simpleUpdate[algoName][day]
fifteenLedgerToUpload[algoName] = tempDic
print("Uploading " + price)
while True:
try:
示例8: print
# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import update [as 别名]
break
except:
print('Ack error')
# was deleting processes from dictionary during iteration
processToDelete = {}
for p in runningProcesses:
print(p + ": Alive = " + str(runningProcesses[p].is_alive()))
if runningProcesses[p].is_alive() == False:
runningProcesses[p].join()
processToDelete[p] = runningProcesses[p]
while True:
try:
pipeline = Firebase("https://sv2.firebaseio.com/hotpipeline")
pipeline.update({p:p})
break
except:
print("Upload Error")
print("Process Joined Length = " + str(len(runningProcesses)))
for p in processToDelete:
del runningProcesses[p]
if pipeEmpty == True and len(runningProcesses) == 0:
break
time.sleep(15)
示例9: runStockAlgorithms
# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import update [as 别名]
def runStockAlgorithms(stock, pricesResults, algorithmsResults, single_algorithmsResults):
lookupCount = 0.0
#decision tracked by days in market...combined to decide
decision = {}
decision["wonky-wonky"] = 0.0
decision["wonky-straight"] = 0.0
decision["straight-wonky"] = 0.0
decision["straight-straight"] = 0.0
highestCorrectness = 0.0
decisionScore = 0.0
#all by trigger
indexUpdate = {}
ledgerUpdate = {}
tradingInfo = {}
for aggregationDuration in algorithmsResults: #aggregation_ninety
for algorithmClass in algorithmsResults[aggregationDuration]: #ssage2
if stock in algorithmsResults[aggregationDuration][algorithmClass]: #acwi
for type in algorithmsResults[aggregationDuration][algorithmClass][stock]: #trigger5
if type not in tradingInfo:
tradingInfo[type] = {}
for day in algorithmsResults[aggregationDuration][algorithmClass][stock][type]: #2016-03-30
#convert to action day
date = time.strptime(day, '%Y-%m-%d')
dt = datetime.fromtimestamp(mktime(date))
buyDate = dt.strftime('%Y-%m-%d')
if buyDate in tradingInfo[type]:
tradingInfo[type][buyDate] += algorithmsResults[aggregationDuration][algorithmClass][stock][type][day]
else:
tradingInfo[type][buyDate] = algorithmsResults[aggregationDuration][algorithmClass][stock][type][day]
for type in tradingInfo: #trigger5
closedLedger = {}
openLedger = {}
algoString = "all_by_trigger:_" + stock + "_" + type
strategyResults = stockStrategy1000(tradingInfo[type], pricesResults, closedLedger, openLedger)
resultDictionary = {"firstPrice":strategyResults["firstPrice"], "region":"world", "algorithmNumber":1000, "daysRight":strategyResults["daysRight"], "daysWrong":strategyResults["daysWrong"], "totalRevenue":strategyResults["totalRevenue"], "closedPositions":closedLedger, "openPositions":openLedger}
if(strategyResults["firstThirtyDayPrice"] == 0.0):
continue
if(strategyResults["firstPrice"] == 0.0):
continue
if(strategyResults["daysRight"] + strategyResults["daysWrong"] < 3):
continue
indexDictionary = {"percentageChangeStockAllTime": (strategyResults["totalRevenue"] - 1000) / 1000, "percentageChangeStockThirty": strategyResults["thirtyDayRevenue"] / strategyResults["firstThirtyDayPrice"], "correctness": strategyResults["daysRight"] / (strategyResults["daysRight"] + strategyResults["daysWrong"]), "price":stock}
day_value = 0
if strategyResults["todayDecision"] == "Buy":
day_value = 1
if strategyResults["todayDecision"] == "Short":
day_value = -1
decision["wonky-wonky"] += (((math.exp(indexDictionary["correctness"]*10)** math.exp(1))/100000000) * day_value if indexDictionary["correctness"] > 0.5 else 0)
decision["wonky-straight"] += (indexDictionary["correctness"]* day_value if indexDictionary["correctness"] > 0.5 else 0)
if(indexDictionary["correctness"] > highestCorrectness):
highestCorrectness = indexDictionary["correctness"]
decisionScore = day_value
elif(indexDictionary["correctness"] == highestCorrectness):
decisionScore += day_value
ledgerUpdate[algoString] = resultDictionary
indexUpdate[algoString] = indexDictionary
print("Uploading " + stock)
while True:
try:
ledger = Firebase("https://sformulateddecision.firebaseIO.com/ledger/" + stock)
ledger.update(ledgerUpdate)
index = Firebase("https://sformulateddecision.firebaseIO.com/index")
index.update(indexUpdate)
break
except:
print ("Upload error...trying again!")
#category_specific (aggregation_ninety
indexUpdate = {}
ledgerUpdate = {}
tradingInfo = {}
for aggregationDuration in algorithmsResults: #aggregation_ninety
if aggregationDuration not in tradingInfo:
#.........这里部分代码省略.........
示例10: int
# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import update [as 别名]
for item in items:
timestamp = item["timestamp"][:4] + "-" + item["timestamp"][4:6] + "-" + item["timestamp"][6:8]
dictToUpload[timestamp] = int(item["views"])
testDate = startDate
while testDate.strftime('%Y-%m-%d') < today.strftime('%Y-%m-%d'):
if testDate.strftime('%Y-%m-%d') not in dictToUpload:
dictToUpload[testDate.strftime('%Y-%m-%d')] = 0
testDate += timedelta(days=1)
f = Firebase('https://sv2.firebaseIO.com/wikipedia/' + term)
while True:
try:
f.update(dictToUpload)
break
except:
print ("Upload error...trying again!")
fb = Firebase('https://sv2.firebaseIO.com/backup/wikipedia/' + datetime.datetime.now().strftime('%Y-%m-%d') + '/' + term)
while True:
try:
fb.update(dictToUpload)
break
except:
print ("Upload error...trying again!")
break
except:
print("Download Error")
示例11: print
# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import update [as 别名]
print("Download Error")
#updated to just get current price for stock
for quote in quotes_to_check:
print("Getting Data for " + quote + "...")
while True:
try:
r = requests.get("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.historicaldata%20where%20symbol%20%3D%20%22" + quotes_to_check[quote] + "%22%20and%20startDate%20%3D%20%22" + last_year + "%22%20and%20endDate%20%3D%20%22" + current_time + "%22&format=json&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=")
# r = requests.get("https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20yahoo.finance.quote%20where%20symbol%20in%20(%22" + quotes_to_check[quote] + "%22)&format=json&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&callback=")
parsed_json = json.loads(r.content)
f = Firebase('https://sv2.firebaseio.com/prices/' + quote)
quotes_to_save = {}
prices = parsed_json['query']['results']['quote']
for quote_specific in prices:
print(quote_specific['Date'])
quotes_to_save[quote_specific['Date']] = {"close":float(quote_specific['Close']), "high":float(quote_specific['High']), "low":float(quote_specific['Low']), "open":float(quote_specific['Open']), "volatility":abs(float(quote_specific['High']) - float(quote_specific['Low']))}
r = f.update(quotes_to_save)
break
except:
print ("Download Error")
while True:
try:
f = Firebase('https://sv2.firebaseIO.com/pipeline')
f.update({"stocks":"stocks"})
break
except:
print ("Upload error...trying again!")
示例12: decrease_volume
# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import update [as 别名]
def decrease_volume(self):
volume= Firebase(METADATA_URL + "volume").get()
volRef = Firebase(METADATA_URL + "volume")
volRef.update(volume - 0.2)
示例13: int
# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import update [as 别名]
reader = csv.reader(csvfile, delimiter = ',', quotechar = '|')
zoneLetter = 'A'
zoneNum = 0
zoneCapacity = 0
zoneOccupied = 0
for row in reader:
if zoneLetter == row[0]:
zoneCapacity = int(row[1])
if not int(row[2]):
zoneOccupied += 1
else:
firebase = Firebase('https://hounds.firebaseio.com/Park/Zones/-TEC' + str(zoneNum) + '/', None)
firebase.update({
"capacity": zoneCapacity,
"occupied": zoneOccupied
})
zoneLetter = row[0]
zoneNum += 1
zoneCapacity = int(row[1])
if not int(row[2]):
zoneOccupied = 1
else:
zoneOccupied = 0
firebase = Firebase('https://hounds.firebaseio.com/Park/Zones/-TEC' + str(zoneNum) + '/', None)
firebase.update({
"capacity": zoneCapacity,
"occupied": zoneOccupied
})
示例14: print
# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import update [as 别名]
r = requests.get("https://access.alchemyapi.com/calls/data/GetNews?apikey=ca669ef629d33657fd7f2c82c671f7c2b819ee4c&start=1457510400&end=1462690800&q.enriched.url.text=" + term + "&count=25&outputMode=json&timeSlice=1d")
parsed_json = json.loads(r.content)
if parsed_json == None:
continue
days = parsed_json["result"]["slices"]
print(days)
for day in days:
news_counts_to_save[current_time.strftime('%Y-%m-%d')] = day
current_time += timedelta(days=1)
f = Firebase('https://sv2.firebaseio.com/news/' + term)
while True:
try:
f.update(news_counts_to_save)
break
except:
print ("Upload error...trying again!")
break
except:
print("Error getting news")
#
#
#
#
#
#
# while True:
# try:
# f = Firebase('https://sv2.firebaseIO.com/status')
示例15: print
# 需要导入模块: from firebase import Firebase [as 别名]
# 或者: from firebase.Firebase import update [as 别名]
for stock in pricesResults:
algorithmsResults = {}
print(stock)
while True:
try:
algorithms = Firebase("https://seagle.firebaseio.com/" + stock)
algorithmsResults = algorithms.get()
break
except:
print("fetch error")
runStockAlgorithms(stock, pricesResults[stock], algorithmsResults )
while True:
try:
pipeline = Firebase("https://sv2.firebaseio.com/hotpipeline")
pipeline.update({stock:stock})
break
except:
print("Upload Error")
# while True:
# while(len(runningProcesses) < 15 and pipeEmpty == False): #16 core machines
# received = subscription.pull(return_immediately=True, max_messages=1)
# messages = [recv[1] for recv in received]
# stock = ""
# for message in messages:
# print("Adding Process: Length = " + str(len(runningProcesses)))
# if message.attributes == {}:
# continue
# stock = message.attributes["stock"]