Load the data from local DB file
()
| 351 | |
| 352 | |
| 353 | def load_records(): |
| 354 | """Load the data from local DB file""" |
| 355 | db, profile_id = get_database() |
| 356 | conn = sqlite3.connect(db) |
| 357 | |
| 358 | # fetch live data from database |
| 359 | with conn: |
| 360 | conn.row_factory = sqlite3.Row |
| 361 | cur = conn.cursor() |
| 362 | cur.execute( |
| 363 | "SELECT * FROM recordActivity " |
| 364 | "WHERE profile_id=:var AND " |
| 365 | "STRFTIME('%Y-%m-%d', created) == " |
| 366 | "STRFTIME('%Y-%m-%d', 'now', 'localtime')", |
| 367 | {"var": profile_id}, |
| 368 | ) |
| 369 | daily_data = cur.fetchall() |
| 370 | |
| 371 | if daily_data: |
| 372 | ordered_data = {today: {}} |
| 373 | |
| 374 | # iterate over hourly rows and re-order data in the required structure |
| 375 | for hourly_data in daily_data: |
| 376 | hourly_data = tuple(hourly_data) |
| 377 | hour = hourly_data[-1][-8:-6] |
| 378 | |
| 379 | ordered_data[today].update( |
| 380 | { |
| 381 | hour: { |
| 382 | "likes": hourly_data[1], |
| 383 | "comments": hourly_data[2], |
| 384 | "follows": hourly_data[3], |
| 385 | "unfollows": hourly_data[4], |
| 386 | "server_calls": hourly_data[5], |
| 387 | } |
| 388 | } |
| 389 | ) |
| 390 | |
| 391 | # load data to the global storage |
| 392 | records.update(ordered_data) |
| 393 | |
| 394 | |
| 395 | def get_record(job, interval): |
no test coverage detected