本文整理汇总了Python中pydblite.Base.open方法的典型用法代码示例。如果您正苦于以下问题:Python Base.open方法的具体用法?Python Base.open怎么用?Python Base.open使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pydblite.Base
的用法示例。
在下文中一共展示了Base.open方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: printdb
# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import open [as 别名]
def printdb(dbpath): # Prints the contents of a PyDBLite database to the console
db = Base(dbpath)
if db.exists():
db.open()
retstr = ""
for obj in db:
retstr += str(obj)
retstr += "\n"
encoded = retstr.encode("utf-8", errors="ignore")
print(encoded)
else:
print("The database does not exist or is corrupt.\n")
示例2: printdb
# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import open [as 别名]
def printdb(dbpath): #Prints the contents of a PyDBLite database to the console
db = Base(dbpath)
if db.exists():
db.open()
retstr = ""
for obj in db:
retstr += str(obj)
retstr += "\n"
print retstr
return retstr
else:
print "The database does not exist or is corrupt.\n"
示例3: likeconvert
# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import open [as 别名]
def likeconvert(likesRoot):
histPath = likesRoot + '/history'
convertcsv2db(likesRoot + '/totals.csv', likesRoot + '/likes.pdl')
db = Base(likesRoot + '/likes.pdl')
db.open()
db.add_field('history', "")
db.add_field('liked', "")
dirContents = os.listdir(histPath)
histFiles = []
for File in dirContents:
if ".csv" in File:
histFiles.append(File)
for histFile in histFiles:
try:
csvfile = open(histPath + '/' + histFile, 'rb')
reader = csv.DictReader(csvfile)
for row in reader:
if histFile.endswith('history.csv'):
recName = histFile[:-11]
print(recName)
if db(userID=recName):
rec = db(userID=recName).pop()
if not rec['liked']:
db.update(rec, liked=row['liked'])
else:
tmpLiked = rec['liked']
tmpLiked += " " + row['liked']
db.update(rec, liked=tmpLiked)
if not rec['history']:
db.update(rec, history=row['messageID'])
else:
tmpHist = rec['history']
tmpHist += " " + row['messageID']
db.update(rec, history=tmpHist)
db.commit()
except csv.Error:
print("Could not open CSV file")
示例4: likeconvert
# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import open [as 别名]
def likeconvert(likesRoot):
histPath = likesRoot + "/history"
convertcsv2db(likesRoot + "/totals.csv", likesRoot + "/likes.pdl")
db = Base(likesRoot + "/likes.pdl")
db.open()
db.add_field("history", "")
db.add_field("liked", "")
dirContents = os.listdir(histPath)
histFiles = []
for File in dirContents:
if ".csv" in File:
histFiles.append(File)
for histFile in histFiles:
try:
csvfile = open(histPath + "/" + histFile, "rb")
reader = csv.DictReader(csvfile)
for row in reader:
if histFile.endswith("history.csv"):
recName = histFile[:-11]
print(recName)
if db(userID=recName):
rec = db(userID=recName).pop()
if not rec["liked"]:
db.update(rec, liked=row["liked"])
else:
tmpLiked = rec["liked"]
tmpLiked += " " + row["liked"]
db.update(rec, liked=tmpLiked)
if not rec["history"]:
db.update(rec, history=row["messageID"])
else:
tmpHist = rec["history"]
tmpHist += " " + row["messageID"]
db.update(rec, history=tmpHist)
db.commit()
except csv.Error:
print("Could not open CSV file")
示例5: get_results_db
# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import open [as 别名]
def get_results_db(clear_cache=False, skip=[]):
cache_file = 'cache/results.pdl'
db = Base(cache_file)
if clear_cache or not db.exists() or os.path.getmtime(cache_file) < os.path.getmtime(results_dir):
warnings.warn('Rebuilding results cache...')
columns = set()
rows = []
p = pathlib.Path(results_dir)
for config_file in p.glob('*.config'):
with config_file.open() as config_fh:
settings_hash = config_file.stem
row = json.loads(config_fh.read())
if settings_hash in skip:
continue
row['hash'] = settings_hash
tests_count = analyze.count(config_file.parent, settings_hash)
row['iostat_cpu'], len_cpu_values = analyze.iostat_cpu(config_file.parent, settings_hash)
row['iperf_result'], len_iperf_values = getattr(analyze, row['iperf_name'])(config_file.parent, settings_hash, row)
if tests_count != len_cpu_values or tests_count != len_iperf_values:
raise analyze.AnalysisException('For test {}, mismatch in cardinality of tests between count ({}), iostat ({}) and iperf ({})'.format(settings_hash, tests_count, len_cpu_values, len_iperf_values), settings_hash)
if len_iperf_values > 0:
min_fairness = row['iperf_result']['fairness'][0] - row['iperf_result']['fairness'][1]
if min_fairness < (1 - 1 / (2 * row['parallelism'])):
warnings.warn('For test {}, fairness has a critical value: {}.'.format(settings_hash, row['iperf_result']['fairness']), RuntimeWarning)
columns = columns | set(row.keys())
rows.append(row)
db.create(*columns, mode='override')
for r in rows:
db.insert(**r)
db.commit()
warnings.warn('Results cache built.')
else:
warnings.warn('Reusing results cache.')
db.open()
return db
示例6: Path
# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import open [as 别名]
from pathlib import Path
from pydblite import Base
if not Path('db').exists():
Path('db').mkdir()
client = Base('db/client.pdl')
if client.exists():
client.open()
else:
client.create('secret', 'redirect_uri', 'name')
authorization_code = Base('db/authorization_code.pdl')
if authorization_code.exists():
authorization_code.open()
else:
authorization_code.create('user_id', 'code', 'expire_time')
token = Base('db/token.pdl')
if token.exists():
token.open()
else:
token.create('user_id', 'access', 'expire_time', 'refresh')
user = Base('db/user.pdl')
if user.exists():
user.open()
else:
user.create('login', 'password_hash', 'name', 'email', 'phone')
clothes = Base('db/clothes.pdl')
示例7: make_graph
# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import open [as 别名]
def make_graph():
""" Make graph from data. """
year = []
lst_jungwat = []
lst_death = []
db = Base('Thai-db.pdl')
db.open()
make_list_year(year, db)
make_list_jungwat(lst_jungwat, db)
i = 0
"""-----------------------------------------------"""
change_death(i, db, lst_jungwat, lst_death)
trace1 = Scatter(
x=year,
y=lst_death,
connectgaps=True,
line=Line(
color='rgb(0, 0, 0)',
width=1
),
name=lst_jungwat[i],
uid='dd3a3c'
)
"""-----------------------------------------------"""
i += 1
lst_death = []
change_death(i, db, lst_jungwat, lst_death)
trace2 = Scatter(
x=year,
y=lst_death,
connectgaps=True,
line=Line(
color='rgb(119, 136, 153)',
width=1
),
name=lst_jungwat[i],
uid='dd3a3c'
)
"""-----------------------------------------------"""
i += 1
lst_death = []
change_death(i, db, lst_jungwat, lst_death)
trace3 = Scatter(
x=year,
y=lst_death,
connectgaps=True,
line=Line(
color='rgb(198, 226, 255)',
width=1
),
name=lst_jungwat[i],
uid='dd3a3c'
)
"""-----------------------------------------------"""
i += 1
lst_death = []
change_death(i, db, lst_jungwat, lst_death)
trace4 = Scatter(
x=year,
y=lst_death,
connectgaps=True,
line=Line(
color='rgb(151, 255, 255)',
width=1
),
name=lst_jungwat[i],
uid='dd3a3c'
)
"""-----------------------------------------------"""
i += 1
lst_death = []
change_death(i, db, lst_jungwat, lst_death)
trace5 = Scatter(
x=year,
y=lst_death,
connectgaps=True,
line=Line(
color='rgb(238, 232, 170)',
width=1
),
name=lst_jungwat[i],
uid='dd3a3c'
)
"""-----------------------------------------------"""
i += 1
lst_death = []
change_death(i, db, lst_jungwat, lst_death)
trace6 = Scatter(
x=year,
y=lst_death,
connectgaps=True,
line=Line(
color='rgb(139, 69, 19)',
width=1
),
name=lst_jungwat[i],
uid='dd3a3c'
)
"""-----------------------------------------------"""
#.........这里部分代码省略.........
示例8: Base
# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import open [as 别名]
# -*- coding: utf-8 -*-
from pydblite import Base
'''
序列化采用cPickle
'''
db = Base("test.db", save_to_file=False)
if db.exists():
db.open()
else:
db.create("name", "age")
db.insert("bob", 10)
index = db.insert(name="alice", age=20)
print db[index] # 按照主键访问record
record = db[1]
db.update(record, name="dellian")
#db.delete(record)
# db.records (所有记录)
# query
for r in db("age") > 10:
print r
示例9: Path
# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import open [as 别名]
from pydblite import Base
from pathlib import Path
if not Path('database').exists():
Path('database').mkdir()
client = Base('database/client.pdl')
if client.exists():
client.open()
else:
client.create('client_id', 'client_secret', 'redirect_uri')
auth_code = Base('database/auth_code.pdl')
if auth_code.exists():
auth_code.open()
else:
auth_code.create('user_id', 'code', 'expired')
token = Base('database/token.pdl')
if token.exists():
token.open()
else:
token.create('user_id', 'access', 'expired', 'refresh')
user = Base('database/user.pdl')
if user.exists():
user.open()
else:
user.create('login', 'password', 'name', 'email', 'phone')
item = Base('database/item1.pdl')
示例10: Path
# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import open [as 别名]
from pathlib import Path
from pydblite import Base
if not Path('db').exists():
Path('db').mkdir()
client = Base('db/client.pdl')
if client.exists():
client.open()
else:
client.create('secret', 'redirect_uri', 'name')
authorization_code = Base('db/authorization_code.pdl')
if authorization_code.exists():
authorization_code.open()
else:
authorization_code.create('user_id', 'code', 'expire_time')
token = Base('db/token.pdl')
if token.exists():
token.open()
else:
token.create('user_id', 'access', 'expire_time', 'refresh')
user = Base('db/user.pdl')
if user.exists():
user.open()
else:
user.create('login', 'password_hash', 'name', 'email', 'phone')
food = Base('db/food.pdl')
示例11: Path
# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import open [as 别名]
from datetime import datetime
from pathlib import Path
from pydblite import Base
if not Path('db').exists():
Path('db').mkdir()
client = Base('db/client.pdl')
if client.exists():
client.open()
else:
client.create('secret', 'redirect_uri', 'name')
authorization_code = Base('db/authorization_code.pdl')
if authorization_code.exists():
authorization_code.open()
else:
authorization_code.create('user_id', 'code', 'expire_time')
token = Base('db/token.pdl')
if token.exists():
token.open()
else:
token.create('user_id', 'access', 'expire_time', 'refresh')
user = Base('db/user.pdl')
if user.exists():
user.open()
else:
user.create('login', 'password_hash', 'name', 'email', 'phone')
示例12: Path
# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import open [as 别名]
from pathlib import Path
from pydblite import Base
if not Path('db').exists():
Path('db').mkdir()
client = Base('db/client.pdl')
if client.exists():
client.open()
else:
client.create('secret', 'redirect_uri', 'name')
authorization_code = Base('db/authorization_code.pdl')
if authorization_code.exists():
authorization_code.open()
else:
authorization_code.create('user_id', 'code', 'expire_time')
token = Base('db/token.pdl')
if token.exists():
token.open()
else:
token.create('user_id', 'access', 'expire_time', 'refresh')
user = Base('db/user.pdl')
if user.exists():
user.open()
else:
user.create('login', 'password_hash', 'name', 'email')
event = Base('db/event.pdl')
示例13: Path
# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import open [as 别名]
from pathlib import Path
from pydblite import Base
if not Path('db').exists():
Path('db').mkdir()
"""
Base for client's application on service via client_id
"""
client_base = Base('db/client_base.pdl')
if client_base.exists():
client_base.open()
else:
client_base.create('secret', 'redirect_uri', 'name')
"""
Base for keeping authorization codes while oauth
"""
authorization_code = Base('db/authorization_code.pdl')
if authorization_code.exists():
authorization_code.open()
else:
authorization_code.create('user_id', 'code', 'expire_time')
"""
Base for access_tokens for authorized users
"""
access_token = Base('db/access_token.pdl')
if access_token.exists():
access_token.open()
else:
access_token.create('user_id', 'access', 'expire_time', 'refresh')
"""
示例14: run_every_10_seconds
# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import open [as 别名]
def run_every_10_seconds():
print 'run_every_10_seconds'
now = datetime.datetime.now()
#record = db(user="")
#now = now.replace(hour=20, minute=0, second=1, microsecond=0)
print now;
db = Base(schedule_table_name)
if db.exists():
db.open()
records = db.records
'''
list_of_records = [];
for record in records:
list_of_records.append(records[record]);
db.delete(list_of_records);
db.commit();
'''
for record in records:
schedule_time = records[record]['schedule_time']
user = records[record]['user']
chat_id = records[record]['chat_id']
enable = records[record]['enable']
print schedule_time,user,chat_id,enable
if enable=='no':
continue
try:
if schedule_time==AM8:
today8am0min = now.replace(hour=8, minute=0, second=0, microsecond=0)
today8am1min = now.replace(hour=8, minute=1, second=0, microsecond=0)
if now >= today8am0min and now <= today8am1min:
kik.send_messages([TextMessage(to=user,chat_id=chat_id,body="scheduled message 8AM")])
except:
pass
try:
if schedule_time==PM8:
print "In 8PM";
today8pm0min = now.replace(hour=20, minute=0, second=0, microsecond=0)
today8pm1min = now.replace(hour=20, minute=1, second=0, microsecond=0)
print today8pm0min;
print today8pm0min;
if now > today8pm0min and now < today8pm1min:
print "Condition matched. Sending message to " + str(user);
kik.send_messages([TextMessage(to=user,chat_id=chat_id,body="scheduled message 8PM")])
except Exception as e:
print (e);
pass
try:
if schedule_time==AM10:
today10am0min = now.replace(hour=10, minute=0, second=0, microsecond=0)
today10am1min = now.replace(hour=10, minute=1, second=0, microsecond=0)
if now > today10am0min and now < today10am1min:
kik.send_messages([TextMessage(to=user,chat_id=chat_id,body="scheduled message 10AM")])
except:
pass
try:
if schedule_time==PM10:
today10pm0min = now.replace(hour=22, minute=0, second=0, microsecond=0)
today10pm1min = now.replace(hour=22, minute=1, second=0, microsecond=0)
if now > today10pm0min and now < today10pm1min:
kik.send_messages([TextMessage(to=user,chat_id=chat_id,body="scheduled message 10PM")])
except:
pass
try:
if schedule_time=='Default':
todaydefault0 = now.replace(hour=DEFAULT_TIME, minute=0, second=0, microsecond=0)
todaydefault1 = now.replace(hour=DEFAULT_TIME, minute=1, second=0, microsecond=0)
if now > todaydefault0 and now < todaydefault1:
kik.send_messages([TextMessage(to=user,chat_id=chat_id,body="scheduled message default")])
except:
pass
示例15: open
# 需要导入模块: from pydblite import Base [as 别名]
# 或者: from pydblite.Base import open [as 别名]
# palavrachavePath = '/Mestrado-2016/tabelas_dump/publicacaokeyword.csv'
# palavrachaveArquivo = open(palavrachavePath, 'r')
#
# publicacaoPath = '/Mestrado-2016/tabelas_dump/publicacao.csv'
# publicacaoArquivo = open(publicacaoPath, 'r')
#
# autoresPath = '/Mestrado-2016/tabelas_dump/autorpublicacao.csv'
# autoresArquivo = open(autoresPath, 'r')
#
infoPath = '/Mestrado-2016/tabelas_dump/infoImportantes2000_2005.csv'
infoArquivo = open(infoPath, 'w')
infoArquivo.write('idpublication;year;keywords;authors\n')
kdb = Base('/Mestrado-2016/tabelas_dump/palavra.pdl')
kdb.open()
kdb.create_index('idpublicacao')
pdb = Base('/Mestrado-2016/tabelas_dump/publicacao.pdl')
pdb.open()
pdb.create_index('idpublicacao')
adb = Base('/Mestrado-2016/tabelas_dump/autor.pdl')
adb.open()
adb.create_index('idpublicacao')
pub = [r for r in pdb if r['ano'] >= 2000 and r['ano'] <= 2005 ]
i = 0
tamanho = len(pub)
for row in pub: