本文整理匯總了Python中db.DB.insert方法的典型用法代碼示例。如果您正苦於以下問題:Python DB.insert方法的具體用法?Python DB.insert怎麽用?Python DB.insert使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類db.DB
的用法示例。
在下文中一共展示了DB.insert方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: AddEvent
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import insert [as 別名]
class AddEvent(tornado.web.RequestHandler):
def initialize(self):
self.webdatabase = DB()
def get(self):
token = self.get_argument('token', None)
platform = self.get_argument('platform', None)
low = self.get_argument('low', None)
high = self.get_argument('high', None)
language = self.get_argument('language', '')
if self.webdatabase.exists(token, platform):
d = dict()
if low:
d['low'] = float(low)
if high:
d['high'] = float(high)
if language:
d['language'] = language
try:
self.webdatabase.update(token, platform, d)
self.write('success')
except Exception as e:
self.write(str(e))
else:
if not low:
low = -1.0
if not high:
high = -1.0
try:
self.webdatabase.insert(token, platform, low, high, language)
self.write('success')
except Exception as e:
self.write(str(e))
示例2: History
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import insert [as 別名]
class History():
def __init__(self):
self.db = DB()
self.solves = self.db.load()
def save(self, timer, scramble, mode):
solve = Solve(timer.begin, timer.gettime(), scramble, mode)
self.solves[mode].append(solve)
self.db.insert(solve)
self._last = solve
def deletelast(self):
self.solves[self._last.mode].pop()
self.db.delete(self._last.rowid)
print("Last solve deleted!\n0.00", end="\r")
def set_dnf(self):
self._last.dnf = True
self.db.setflag("dnf", self._last.rowid)
def set_plustwo(self):
self._last.plustwo = True
self.db.setflag("plustwo", self._last.rowid)
def getlast(self, mode, n):
return self.solves[mode][-n:]
def close(self):
self.db.close()
示例3: __init__
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import insert [as 別名]
class Notes:
#Database names
database = "NOTES"
note_id = "id"
data = "data"
name= "name"
password = "password"
#Actual Note ID
noteID = None
def __init__(self,noteID):
self.DB = DB(self.database, self.note_id)
self.noteID = noteID
def noteID(self):
return noteID
def index(self):
return self.DB.select_all([self.note_id ,self.name],None,None,None)
def select_note(self):
row = self.DB.select_one(self.noteID, [self.data])
if row:
return str(row[0])
return None
def update_note(self, text):
return self.DB.update(self.noteID,[self.data],[text])
def update_note_name(self,name):
return self.DB.update(self.noteID,[self.name],[name])
def add_note(self,text,name):
return self.DB.insert([self.data,self.name,self.password],[text,name,None])
def remove_note(self):
return self.DB.remove(self.noteID)
def check_password(self, password):
row = self.DB.select_one(self.noteID,[self.password])
actual_password = row[0]
if actual_password != None:
actual_password = str(actual_password)
if password != None and str(password) == actual_password:
return True
return False
def set_password(self,new_pass):
return self.DB.update(self.noteID,[self.password],[new_pass])
def is_locked(self):
row = self.DB.select_one(self.noteID,[self.password])
password = row[0]
if password==None or len(str(password)) == 0:
return False
else:
return True
示例4: task
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import insert [as 別名]
def task(addr, db_table_name):
""" 向addr發送數據,然後接收數據"""
# 創建socket
sock = socket.socket()
try:
# 發起連接,記錄連接發起的時間
start_conn_time = round(time.time()*1000000)
sock.connect(addr)
# 記錄連接成功的時間
conn_comp_time = round(time.time()*1000000)
# 準備要發送json數據
d = {'start_conn_time': start_conn_time,
'conn_comp_time': conn_comp_time,}
msg = pack_dict(d)
# 記錄發起請求的時間
request_time = round(time.time()*1000000)
# 發送數據
complete_send(sock, msg)
# 開始接收數據
bmsg = complete_recv(sock)
# 關閉socket
sock.close()
# 記錄接收完成的時間
request_comp_time = round(time.time()*1000000)
# 解包數據
d = unpack_bytes(bmsg)
# 將發起請求和請求返回時間插入字典
d['request_time'] = request_time
d['request_comp_time'] = request_comp_time
# 將數據保存到數據庫
db = DB(db_table_name)
db.insert(**d)
db.close()
except socket.error as e:
print(sock.getsockname(),'上連接發生錯誤,', e)
示例5: sign_service
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import insert [as 別名]
def sign_service():
# 設置程序工作目錄為當前程序所在目錄
set_work_dir()
while True:
if have_signed_already():
sleep_until_tomorrow_sign_time()
if not is_sign_time_now():
sleep_until_today_sign_time()
try:
gold_num = sign()
except TimeoutError:
sleep(5*50)
except RepeatSignError:
sleep_until_tomorrow_sign_time()
else:
db = DB(database='sign_records.db')
db.insert(gold=gold_num)
db.close()
sleep_until_tomorrow_sign_time()
示例6: Counter
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import insert [as 別名]
class Counter(object):
_db = None
def __init__(self):
self._db = DB("mongodb://rv005UI:[email protected]:10012/IssueTracker")
self._db.database("IssueTracker")
self._db.collection("counter")
def create(self):
if not (self._db.check({"_id": "user"})):
self._db.insert({"_id": "user", "next": 0})
if not (self._db.check({"_id": "backlog"})):
self._db.insert({"_id": "backlog", "next": 0})
if not (self._db.check({"_id": "issue"})):
self._db.insert({"_id": "issue", "next": 0})
if not (self._db.check({"_id": "subissue"})):
self._db.insert({"_id": "subissue", "next": 0})
if not (self._db.check({"_id": "comment"})):
self._db.insert({"_id": "comment", "next": 0})
def _next(self, name):
document = self._db.update_and_select({"_id": name}, {"$inc": {"next": 1}})
return document["next"]
def user(self):
return self._next("user")
def backlog(self):
return self._next("backlog")
def issue(self):
return self._next("issue")
def subissue(self):
return self._next("subissue")
def comment(self):
return self._next("comment")
示例7: add
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import insert [as 別名]
def add():
output = {"title":"",'id':'',"response":""}
url = request.form['url']
feed = feedparser.parse(url)
try:
title = feed['feed']['title']
db = DB()
output['id'] = db.insert(url,title)
output['title'] = title
output['response'] = 'ok'
except IndexError :
output['response'] = 'Wrong feed address'
except KeyError :
output['response'] = 'Wrong feed address'
return json.dumps(output)
示例8: DB
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import insert [as 別名]
from db import DB
database = DB()
try:
if None == database.insert('hello', 'world', 12, 23, 's'):
print("OK")
if None == database.insert('fuck', 'uuuuu', 2, 333, 'b'):
print("OK")
result = database.delete('fuck', 'uuuuu', 'b')
print(result)
result = database.delete('j', 'b', 'c')
print(result)
database.close()
except Exception as e:
print(str(e))
示例9: MalwareCollector
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import insert [as 別名]
from MalwareCollector import MalwareCollector
from db import DB
mc = MalwareCollector(country="brazil")
mydb = DB()
myTrendsList = mc.getTrends()
myTweets = mc.searchTweets(query=myTrendsList[1], max_tweets=100)
print("Trendings: ", myTrendsList)
mydata = {}
for tweets in myTweets:
# preparing to insert
mydata = {
"text": tweets["text"].encode("utf-8"),
"created_at": tweets["created_at"],
"user": tweets["user"],
"geo": tweets["geo"],
"coordinates": tweets["coordinates"],
}
# inserting
mydb.insert(mydata)
# just printing
print(tweets["text"].encode("utf-8"))
print(tweets["user"])
print(tweets["created_at"])
print(tweets["geo"])
print(tweets["coordinates"])
print("--------------")
示例10: log
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import insert [as 別名]
conn.setsockopt(socket.SOL_SOCKET, socket.SO_SNDTIMEO, struct.pack('ii', 30, 0))
except:
pass
log(str(i) + ". " + t() + " client connected from " + str(addr) + "\n")
connectionthread(conn, addr, phones).start()
i += 1
if i % 1000 == 0:
try:
db = open("webkeyusers.txt", "w");
mysqldb = DB('114.112.63.174', 3306, 'root', 'doododAAAAA', 'cloudphone')
tbname = 'tb_device'
for username in phones:
db.write(username + " " + phones[username].random + "\n")
mysqldb.insert(tbname, {'device_name': username,
'random_code': phones[username].random,
'collect_time': time.strftime('%Y-%m-%d', time.localtime(time.time())),
'state':1
})
db.close()
mysqldb.commit()
print "SAVED DATABASE"
except:
print "SAVING DATABASE FAILED"
# print i
except KeyboardInterrupt:
try:
f.close()
except:
pass
break
except socket.error:
示例11: __init__
# 需要導入模塊: from db import DB [as 別名]
# 或者: from db.DB import insert [as 別名]
class CalendarLog:
#Database names
database = "CALENDAR"
entry_id = "id"
data = "data"
date= "date"
password = "password"
#Actual log ID
logID = None
def __init__(self,logID):
self.DB = DB(self.database, self.entry_id)
self.logID = logID
def logID(self):
return logID
def index(self):
return self.DB.select_all([self.entry_id ,self.date],None,None,None)
def select_log(self):
row = self.DB.select_one(self.logID, [self.data, self.date])
return row
def select_logs_range(self,start,end,limit):
if start and end:
return self.DB.select_all([self.entry_id ,self.date, self.data],[self.date+" >=", "AND "+self.date+" <="],[start,end],limit)
elif start:
return self.DB.select_all([self.entry_id ,self.date, self.data],[self.date+" >="],[start],limit)
elif end:
return self.DB.select_all([self.entry_id ,self.date, self.data],[self.date+" <="],[end],limit)
else:
return self.DB.select_all([self.entry_id ,self.date, self.data],None,None,limit)
def update_log(self, text):
return self.DB.update(self.logID,[self.data],[text])
def update_log_date(self,date):
return self.DB.update(self.logID,[self.date],[date])
def add_log(self,text,date):
return self.DB.insert([self.data,self.date,self.password],[text,date,None])
def remove_log(self):
return self.DB.remove(self.logID)
def check_password(self, password):
row = self.DB.select_one(self.logID,[self.password])
actual_password = row[0]
if actual_password != None:
actual_password = str(actual_password)
if password != None and str(password) == actual_password:
return True
return False
def set_password(self,new_pass):
return self.DB.update(self.logID,[self.password],[new_pass])
def is_locked(self):
row = self.DB.select_one(self.logID,[self.password])
password = row[0]
if password==None or len(str(password)) == 0:
return False
else:
return True