-
Notifications
You must be signed in to change notification settings - Fork 0
/
TumblrUnfollower.py
65 lines (53 loc) · 1.46 KB
/
TumblrUnfollower.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import pytumblr
import os
from dotenv import load_dotenv
load_dotenv()
CONSUMER_PUBLIC=os.getenv("CONSUMER_PUBLIC")
CONSUMER_SECRET=os.getenv("CONSUMER_SECRET")
OLD_CLIENT_TOKEN=os.getenv("OLD_CLIENT_TOKEN")
OLD_CLIENT_SECRET=os.getenv("OLD_CLIENT_SECRET")
oldClient = pytumblr.TumblrRestClient(
CONSUMER_PUBLIC,
CONSUMER_SECRET,
OLD_CLIENT_TOKEN,
OLD_CLIENT_SECRET
)
_limit = 20
def unfollowStaleBlogs():
_offset = 1200
while True:
print(_offset)
following = oldClient.following(offset=_offset)
blogs = following['blogs']
if blogs == []:
break
for blog in blogs:
if blog['updated'] < 1672604736:
url = blog['url']
print('unfollowing' + url)
oldClient.unfollow(url)
_offset = _offset + 20
def writeFollowedBlogUrlsToDisk():
_offset = None
with open('data/meta.txt', 'r') as file:
_offset = int(file.readline())
with open('assets/followed_blogs.txt', 'r+') as file:
if _offset is None:
_offset = len(file.readlines())
while True:
try:
following = oldClient.following(limit=_limit, offset=_offset)
blogs = following['blogs']
if blogs == []:
break
for blog in blogs:
url = blog['url']
if(url):
file.write(url + "\n")
_offset = _offset + _limit
except:
print("limit exceeded, offset=", _offset)
break
with open('data/meta.txt', 'w') as metaFile:
metaFile.write(str(_offset))
writeFollowedBlogUrlsToDisk()