Instagram-to-discord icon indicating copy to clipboard operation
Instagram-to-discord copied to clipboard

Please configure environment variables correctly

Open Swastik2442 opened this issue 3 years ago • 1 comments

I am getting the error "Please configure environment variables correctly" even after I am configured them correctly. Please help.

Swastik2442 avatar May 08 '21 14:05 Swastik2442

`#!/usr/bin/python

INSTAGRAM_USERNAME = os.environ.get('ig_loki2442')

----------------------- Do not modify under this line -----------------------

def get_user_fullname(html): return html.json()["graphql"]["user"]["full_name"]

def get_total_photos(html): return int(html.json()["graphql"]["user"]["edge_owner_to_timeline_media"]["count"])

def get_last_publication_url(html): return html.json()["graphql"]["user"]["edge_owner_to_timeline_media"]["edges"][0]["node"]["shortcode"]

def get_last_photo_url(html): return html.json()["graphql"]["user"]["edge_owner_to_timeline_media"]["edges"][0]["node"]["display_url"]

def get_last_thumb_url(html): return html.json()["graphql"]["user"]["edge_owner_to_timeline_media"]["edges"][0]["node"]["thumbnail_src"]

def get_description_photo(html): return html.json()["graphql"]["user"]["edge_owner_to_timeline_media"]["edges"][0]["node"]["edge_media_to_caption"]["edges"][0]["node"]["text"]

def webhook(webhook_url, html): # for all params, see https://discordapp.com/developers/docs/resources/webhook#execute-webhook # for all params, see https://discordapp.com/developers/docs/resources/channel#embed-object data = {} data["embeds"] = [] embed = {} embed["color"] = 15467852 embed["title"] = "New pic of @"+INSTAGRAM_USERNAME+"" embed["url"] = "https://www.instagram.com/p/" +
get_last_publication_url(html)+"/" embed["description"] = get_description_photo(html) # embed["image"] = {"url":get_last_thumb_url(html)} # unmark to post bigger image embed["thumbnail"] = {"url": get_last_thumb_url(html)} data["embeds"].append(embed) result = requests.post(webhook_url, data=json.dumps( data), headers={"Content-Type": "application/json"}) try: result.raise_for_status() except requests.exceptions.HTTPError as err: print(err) else: print("Image successfully posted in Discord, code {}.".format( result.status_code))

def get_instagram_html(INSTAGRAM_USERNAME): headers = { "Host": "www.instagram.com", "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.11 (KHTML, like Gecko) Chrome/23.0.1271.64 Safari/537.11" } html = requests.get("https://www.instagram.com/" + INSTAGRAM_USERNAME + "/feed/?__a=1", headers=headers) return html

def main(): try: html = get_instagram_html(INSTAGRAM_USERNAME) if(os.environ.get("LAST_IMAGE_ID") == get_last_publication_url(html)): print("Not new image to post in discord.") else: os.environ["LAST_IMAGE_ID"] = get_last_publication_url(html) print("New image to post in discord.") webhook(os.environ.get("https://discord.com/api/webhooks/840585579439718410/Xcmt2qD7lu0FtsE5Sa8uOrMasZI-9T99Y85CObkMPEq3sL_qHOPaIiViEbu42hOZhuJ5"), get_instagram_html(INSTAGRAM_USERNAME)) except Exception as e: print(e)

if name == "main": if os.environ.get('ig_loki2442') != None and os.environ.get('https://discord.com/api/webhooks/840585579439718410/Xcmt2qD7lu0FtsE5Sa8uOrMasZI-9T99Y85CObkMPEq3sL_qHOPaIiViEbu42hOZhuJ5') != None: while True: main() time.sleep(float(os.environ.get('1.5') or 600)) # 600 = 10 minutes else: print('Please configure environment variables properly!') `

Swastik2442 avatar May 08 '21 14:05 Swastik2442