-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDanbot.py
49 lines (41 loc) · 1.43 KB
/
Danbot.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
import time
import requests
import tweepy
import urllib
import os
import random
page = 1
# Edit the tags=. It's only limited to two tags, though.
url = 'https://danbooru.donmai.us/posts.json?tags=example_tag_1 example_tag_2&limit=10&page='
# Enter your twitter credentials here, as strings.
consumer_key =
consumer_secret =
access_key =
access_secret =
auth = tweepy.OAuthHandler(consumer_key, consumer_secret)
auth.set_access_token(access_key, access_secret)
api = tweepy.API(auth)
while True:
try:
random.seed()
jsURL = url + str(random.randint(1,1000))
response = requests.get(jsURL)
pageTable = response.json()
arrayNum = random.randint(0,9)
# If you want to expand on this,
# https://danbooru.donmai.us/posts.json?tags=yakumo_ran&page=1000&limit=1
# is an example post json table.
imageSource = pageTable[arrayNum]["file_url"]
imageURL = "http://danbooru.donmai.us" + imageSource
print imageURL
sourceURL = "http://danbooru.donmai.us/posts/" + str(pageTable[arrayNum]["id"])
print sourceURL
urllib.urlretrieve(imageURL, 'image.jpg')
# Fill the empty string with the hashtags you want.
tweetString = sourceURL + " "
api.update_with_media('image.jpg', status=tweetString)
os.remove('image.jpg')
# You can replace the number with however often you want to post. Limited to 500 requests/hour.
time.sleep(1800)
except tweepy.error.TweepError:
print "Image too large, finding a different image..."