本文整理汇总了Python中dataset.connect方法的典型用法代码示例。如果您正苦于以下问题:Python dataset.connect方法的具体用法?Python dataset.connect怎么用?Python dataset.connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类dataset
的用法示例。
在下文中一共展示了dataset.connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: add_shared_args
# 需要导入模块: import dataset [as 别名]
# 或者: from dataset import connect [as 别名]
def add_shared_args(parser):
parser.add_argument("query")
parser.add_argument("--db",
type=dataset.connect,
help="SQLAlchemy connection string. Default: " + DEFAULT_DB,
default=DEFAULT_DB)
parser.add_argument("--throttle",
type=int,
default=15,
help="""Wait X seconds between requests.
Default: 15 (to stay under rate limits)""")
parser.add_argument("--credentials",
nargs=4,
help="""
Four space-separated strings for {}.
Defaults to environment variables by those names.
""".format(", ".join(CREDENTIAL_NAMES))
)
parser.add_argument("--store-raw",
help="Store raw tweet JSON, in addition to excerpted fields.",
action="store_true")
parser.add_argument("--quiet",
help="Silence logging.",
action="store_true")
示例2: create_app_info_dict
# 需要导入模块: import dataset [as 别名]
# 或者: from dataset import connect [as 别名]
def create_app_info_dict():
dlist = []
conn = dataset.connect(config.APP_INFO_SQLITE_FILE)
print("Creating app-info dict")
for k, v in config.source_files.items():
d = pd.read_csv(v, index_col='appId')
d['store'] = k
if 'permissions' not in d.columns:
print(k, v, d.columns)
d.assign(permissions=["<not recorded>"]*len(d))
d.columns = d.columns.str.lower().str.replace(' ', '-').str.replace('-', '_')
dlist.append(d)
pd.concat(dlist).to_sql('apps', conn.engine, if_exists='replace')
conn.engine.execute('create index idx_appId on apps(appId)')
示例3: setup_db
# 需要导入模块: import dataset [as 别名]
# 或者: from dataset import connect [as 别名]
def setup_db(connection_string):
db = dataset.connect(connection_string)
connections = db['connection']
users = db['user']
tweets = db['tweet']
medias = db['media']
mentions = db['mention']
urls = db['url']
hashtags = db['hashtag']
tweets.create_index(['tweet_id'])
medias.create_index(['tweet_id'])
mentions.create_index(['user_id'])
mentions.create_index(['mentioned_user_id'])
urls.create_index(['tweet_id'])
hashtags.create_index(['tweet_id'])
users.create_index(['user_id'])
connections.create_index(['friend_id'])
connections.create_index(['follower_id'])
return db
示例4: setup_db
# 需要导入模块: import dataset [as 别名]
# 或者: from dataset import connect [as 别名]
def setup_db(connection_string):
db = dataset.connect(connection_string)
pages = db['page']
users = db['user']
posts = db['post']
comments = db['comment']
interactions = db['interaction']
users.create_index(['user_id'])
posts.create_index(['post_id'])
comments.create_index(['comment_id'])
comments.create_index(['post_id'])
interactions.create_index(['comment_id'])
interactions.create_index(['post_id'])
interactions.create_index(['user_id'])
return db
示例5: start
# 需要导入模块: import dataset [as 别名]
# 或者: from dataset import connect [as 别名]
def start(self):
"""
Initialize db and session monitor thread
"""
global db
log.info(":SYS:Starting W.I.L.L")
db_url = self.configuration_data["db_url"]
log.info(":SYS:Connecting to database")
db = dataset.connect(db_url, engine_kwargs={"pool_recycle": 1})
core.db = db
API.db = db
web.db = db
start_time = self.now.strftime("%I:%M %p %A %m/%d/%Y")
web.start_time = start_time
log.info(":SYS:Starting W.I.L.L core")
core.initialize(db)
log.info(":SYS:Starting sessions parsing thread")
core.sessions_monitor(db)
log.info(":SYS:W.I.L.L started")
示例6: __init__
# 需要导入模块: import dataset [as 别名]
# 或者: from dataset import connect [as 别名]
def __init__(self):
""""""
self.exchange = ccxt.poloniex()
self.exchange.load_markets()
self.delay_seconds = self.exchange.rateLimit / 1000
self.symbols = self.exchange.markets
self.timeframe = '1d'
self.db_url = 'sqlite:///databases/market_prices.db'
self.deques = dict()
self.ohlcv = dict()
self.database = dataset.connect(self.db_url)
ensure_dir('databases')
for symbol in self.symbols:
if self.exchange.has['fetchOHLCV']:
print('Obtaining OHLCV data')
data = self.exchange.fetch_ohlcv(symbol, self.timeframe)
data = list(zip(*data))
data[0] = [datetime.datetime.fromtimestamp(ms / 1000)
for ms in data[0]]
self.ohlcv[symbol] = data
time.sleep(self.delay_seconds)
else:
print('No OHLCV data available')
self.deques[symbol] = deque()
if len(self.database[symbol]):
for e in self.database[symbol]:
entry = (e['bid'], e['ask'], e['spread'], e['time'])
self.deques[symbol].append(entry)
del self.database
self.thread = threading.Thread(target=self.__update)
self.thread.daemon = True
self.thread.start()
示例7: __update
# 需要导入模块: import dataset [as 别名]
# 或者: from dataset import connect [as 别名]
def __update(self):
"""
https://github.com/ccxt-dev/ccxt/wiki/Manual#market-price
"""
self.database = dataset.connect(self.db_url)
while True:
for symbol in self.symbols:
start_time = time.clock()
orders = self.exchange.fetch_order_book(symbol)
bid = orders['bids'][0][0] if len(orders['bids']) > 0 else None
ask = orders['asks'][0][0] if len(orders['asks']) > 0 else None
spread = (ask - bid) if (bid and ask) else None
dtime = datetime.datetime.now()
self.deques[symbol].append((bid, ask, spread, dtime))
self.database.begin()
try:
self.database[symbol].insert({
'ask': ask,
'bid': bid,
'spread': spread,
'time': dtime
})
self.database.commit()
except:
self.database.rollback()
time.sleep(self.delay_seconds - (time.clock() - start_time))
示例8: start
# 需要导入模块: import dataset [as 别名]
# 或者: from dataset import connect [as 别名]
def start(cls):
cls.db = dataset.connect(cls.database_url)
super().start()
示例9: conn
# 需要导入模块: import dataset [as 别名]
# 或者: from dataset import connect [as 别名]
def conn():
warehouse = dataset.connect(config.WAREHOUSE_URL)
for table in warehouse.tables:
warehouse[table].delete()
return {'warehouse': warehouse}
示例10: open_spider
# 需要导入模块: import dataset [as 别名]
# 或者: from dataset import connect [as 别名]
def open_spider(self, spider):
if spider.conf and spider.conn:
self.__conf = spider.conf
self.__conn = spider.conn
else:
# For runs trigered by scrapy CLI utility
self.__conf = helpers.get_variables(config, str.isupper)
self.__conn = {'warehouse': dataset.connect(config.WAREHOUSE_URL)}
示例11: cli
# 需要导入模块: import dataset [as 别名]
# 或者: from dataset import connect [as 别名]
def cli(argv):
# Prepare conf dict
conf = helpers.get_variables(config, str.isupper)
# Prepare conn dict
conn = {
'warehouse': dataset.connect(config.WAREHOUSE_URL),
}
# Get and call collector
collect = importlib.import_module('collectors.%s' % argv[1]).collect
collect(conf, conn, *argv[2:])
示例12: run
# 需要导入模块: import dataset [as 别名]
# 或者: from dataset import connect [as 别名]
def run(consumer_key, consumer_secret, access_key, access_secret,
connection_string, threshold=5000, seed_only=True):
db = dataset.connect(connection_string)
api = get_api(consumer_key, consumer_secret, access_key, access_secret)
if seed_only:
is_seed = 1
else:
is_seed = 0
user_table = db['user']
users = user_table.find(user_table.table.columns.friends_count < threshold,
friends_collected=0, is_seed=is_seed)
users = [u for u in users]
all_users = len(users)
remaining = all_users
for u in users:
try:
print('Getting friend ids for ' + u['screen_name'])
next, prev, friend_ids = get_friend_ids(
api, screen_name=u['screen_name'])
print('Adding ' + str(len(friend_ids)) + ' user ids to db')
insert_if_missing(db, user_ids=friend_ids)
print('Creating relationships for ' + str(u['user_id']))
create_connections(db, u['user_id'], friend_ids=friend_ids)
update_dict = dict(id=u['id'], friends_collected=1)
user_table.update(update_dict, ['id'])
# Can only make 15 calls in a 15 minute window to this endpoint
remaining -= 1
time_left = remaining / 60.0
print(str(time_left) + ' hours to go')
print('Sleeping for 1 minute, timestamp: ' + str(datetime.now()))
time.sleep(60)
except:
continue
示例13: run
# 需要导入模块: import dataset [as 别名]
# 或者: from dataset import connect [as 别名]
def run(consumer_key, consumer_secret, access_key, access_secret,
connection_string):
db = dataset.connect(connection_string)
api = get_api(consumer_key, consumer_secret, access_key, access_secret)
user_table = db['user']
users = user_table.find(user_table.table.columns.user_id != 0,
profile_collected=0)
users = [u for u in users]
if len(users) == 0:
print('No users without profiles')
return None
ids_to_lookup = []
for user in users:
ids_to_lookup.append(user['user_id'])
if len(ids_to_lookup) == 100:
print('Getting profiles')
profiles = get_profiles(api, user_ids=ids_to_lookup)
print('Updating 100 profiles')
upsert_profiles(db, profiles)
ids_to_lookup = []
print('Sleeping, timestamp: ' + str(datetime.now()))
time.sleep(5)
print('Getting profiles')
profiles = get_profiles(api, user_ids=ids_to_lookup)
print('Updating ' + str(len(ids_to_lookup)) + ' profiles')
upsert_profiles(db, profiles)
print('Finished getting profiles')
示例14: help
# 需要导入模块: import dataset [as 别名]
# 或者: from dataset import connect [as 别名]
def help(bot, update):
'''Echo the help string'''
bot.sendMessage(update.message.chat_id, help_str)
#def socket_io_thread(bot,session_id, chat_id ):
# socketIO = SocketIO(SERVER_URL, 80)
# log.info("In socket_io thread")
# socketIO.on('connect', lambda: socketIO.emit("get_updates", session_id))
# socketIO.on('update', lambda x: bot.sendMessage(chat_id, (x["value"])))
# socketIO.on('disconnect', lambda x: bot.sendMessage(chat_id, "Update server has disconnected"))
# socketIO.on('debug', lambda x: log.info("Got debug message {0} from socketIO".format(x["value"])))
# socketIO.wait()
示例15: __connect_alarms
# 需要导入模块: import dataset [as 别名]
# 或者: from dataset import connect [as 别名]
def __connect_alarms(self):
""" Connecting to a SQLite database table 'alarms'. """
alarms_table = dataset.connect(self.db_file)['alarms']
return alarms_table