-
Notifications
You must be signed in to change notification settings - Fork 0
/
wpfields.py
47 lines (35 loc) · 1.18 KB
/
wpfields.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import datetime
import subprocess
BATCH_SIZE = 9
def next_batch(offset):
process = os.popen(f"vip @stanforddaily.develop -- wp post list --field=ID --offset={offset} --posts_per_page={BATCH_SIZE}")
output = process.read()
process.close()
return output.strip().splitlines()
def all_post_ids():
offset = 0
batches = []
while True:
batch = next_batch(offset)
if not batch or offset > 36:
break
batches.extend(batch)
offset += BATCH_SIZE
return batches
# print("Starting at", datetime.datetime.now())
# print(posts)
# print("Finished at", datetime.datetime.now())
def primary_term_categories(post_id):
process = os.popen(f"vip @stanforddaily.develop -- wp post meta get {post_id} _primary_term_category")
output = process.read()
process.close()
return output.strip().splitlines()
def all_primary_term_categories():
posts = {x: "" for x in all_post_ids()}
for post_id in posts.keys():
posts[post_id] = primary_term_categories(post_id)
return posts
print("Starting at", datetime.datetime.now())
print(all_primary_term_categories())
print("Finished at", datetime.datetime.now())