コード例 #1
0
                                              post["timestamp"])
        if post["timestamp"] < threads[thread_id]["post_first_timestamp"]:
            threads[thread_id]["post_first"] = post["msgid"]
            threads[thread_id]["post_first_timestamp"] = post["timestamp"]

        if post["timestamp"] > threads[thread_id]["post_last_timestamp"]:
            threads[thread_id]["post_last"] = post["msgid"]
            threads[thread_id]["post_last_timestamp"] = post["timestamp"]

        done += 1

    db.commit()
    if limit and done > limit:
        break

print("Updating thread metadata...")
db.commit()
for thread_id, data in threads.items():
    del data["post_last_timestamp"]
    del data["post_first_timestamp"]

    db.update("threads_usenet",
              data=data,
              where={"id": thread_id},
              commit=False)

print("Committing thread updates to database...")
db.commit()

print("Done!")
コード例 #2
0
ファイル: import_4plebs.py プロジェクト: pgr-me/4cat
    else:
        if thread["timestamp"] < exists["timestamp"]:
            thread["is_sticky"] = exists["is_sticky"]
            thread["is_closed"] = exists["is_closed"]
        thread["post_last"] = max(int(thread.get("post_last") or 0),
                                  int(exists.get("post_last") or 0))
        thread["timestamp_modified"] = max(
            int(thread.get("timestamp_modified") or 0),
            int(exists.get("timestamp_modified") or 0))
        thread["timestamp_modified"] = max(
            int(thread.get("timestamp_archived") or 0),
            int(exists.get("timestamp_archived") or 0))
        thread["timestamp"] = min(int(thread.get("timestamp") or 0),
                                  int(exists.get("timestamp") or 0))

        db.update("threads_" + args.datasource,
                  data=thread,
                  where={"id": thread_id})

print("Updating thread statistics.")
db.execute(
    "UPDATE threads_" + args.datasource +
    " AS t SET num_replies = ( SELECT COUNT(*) FROM posts_" + args.datasource +
    " AS p WHERE p.thread_id = t.id) WHERE t.id IN %s",
    (tuple(threads.keys()), ))
db.execute(
    "UPDATE threads_" + args.datasource +
    " AS t SET num_images = ( SELECT COUNT(*) FROM posts_" + args.datasource +
    " AS p WHERE p.thread_id = t.id AND image_file != '') WHERE t.id IN %s",
    (tuple(threads.keys()), ))