repl.it
@pieromqwerty/

AutoGram

Python

No description

fork
loading
Files
  • main.py
  • 00000001.jpg
  • data.json
  • tags.txt
  • Packager files
  • requirements.txt
main.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
import json
import requests
from InstagramAPI import InstagramAPI
import os


#headers for image content request
headers = {
    'authority': 'www.instagram.com',
    'cache-control': 'max-age=0',
    'upgrade-insecure-requests': '1',
    'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/77.0.3865.10 Safari/537.36 Edg/77.0.235.5',
    'sec-fetch-mode': 'navigate',
    'sec-fetch-user': '?1',
    'accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3',
    'sec-fetch-site': 'none',
    'accept-encoding': 'gzip, deflate, br',
    'accept-language': 'en-US,en;q=0.9',
}

params = (
    ('__a', '1'),
)

#getting image content
response = requests.get('https://www.instagram.com/explore/tags/dankmemes/', headers=headers, params=params)
responseModern = response.content
content = responseModern.decode('utf-8')
j = json.loads(content)

#parsing out image location
graphql = j['graphql']
hashtag = graphql['hashtag']
edge_hashtag_to_media = hashtag['edge_hashtag_to_media']
edges = edge_hashtag_to_media['edges']
lenode = edges[1]
node = lenode['node']
img_link = node['display_url']
print(img_link)

#getting image from url
f = open('00000001.jpg','wb')
f.write(requests.get(img_link).content)
f.close()

#logging in
InstagramAPI = InstagramAPI('duck.mems', 'Qazwaz123')
InstagramAPI.login()

#opening tags file and uploading to instagram
f = open("tags.txt", "r")
photo_path = '00000001.jpg'
caption = f.read()
InstagramAPI.uploadPhoto(photo_path, caption=caption)
?