Skip to content

Instantly share code, notes, and snippets.

@thisiskeanyvy
Created October 5, 2021 15:21
Show Gist options
  • Save thisiskeanyvy/b812f11ca93a1ca40e757c4051bc7128 to your computer and use it in GitHub Desktop.
Save thisiskeanyvy/b812f11ca93a1ca40e757c4051bc7128 to your computer and use it in GitHub Desktop.
Instagram autopost
import config
import urllib.request
from datetime import date
from instabot import Bot
#variables
today = date.today();
bot = Bot()
bot.login(username = "yourusername", password = "yourpassword");
def program():
init();
nbjours();
datetime();
comptenbjours();
post();
end();
def init():
print("""
InstaPost par Keany Vy KHUN
""");
def nbjours():
global nbjours
readfile = open("jours.txt", "r+");
nbjours = int(float(readfile.readline()));
readfile.close();
def comptenbjours():
ajoutdejours = nbjours + 1;
compteurnbjours = str(ajoutdejours);
file = open("jours.txt", "w+");
file.write(compteurnbjours);
file.close();
def datetime():
global time
time = today.strftime("%d %b %Y");
def post():
nameimage = today.strftime("%d%b%Y");
readfile = open("jours.txt", "r+");
url = 'https://source.unsplash.com/1080x1080/?architecture,art,monument'
urllib.request.urlretrieve(url, 'posts/'+ nameimage +'.jpg')
bot.upload_photo("posts/"+ nameimage +".jpg", caption ="Publication journalière du : " + time + " et Jour n°"+ readfile.readline() + " du défi #daily par @thisiskeanyvy");
def daily():
readfile = open("daily.txt", "r+");
if readfile.readline() == today.strftime("%d-%b-%Y"):
print("""
Publication déjà éffectuée
""");
elif readfile.readline() != today.strftime("%d-%b-%Y"):
program();
def end():
date = today.strftime("%d-%b-%Y");
file = open("daily.txt", "w+");
file.write(date);
file.close();
daily();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment