Image3 / app.py
nagasurendra's picture
Create app.py
19ce28f verified
raw
history blame
1.19 kB
from flask import Flask, render_template, request, jsonify
import os
import cv2
import base64
import requests
app = Flask(__name__)
# Instagram credentials (use your Instagram bot or automation method here)
INSTAGRAM_USERNAME = 'your_username'
INSTAGRAM_PASSWORD = 'your_password'
@app.route('/')
def index():
return render_template('index.html')
@app.route('/capture', methods=['POST'])
def capture():
image_data = request.form['image']
# Decode the image from base64 to save it
img_data = base64.b64decode(image_data.split(',')[1])
with open("static/images/captured_image.jpg", "wb") as f:
f.write(img_data)
return jsonify({"message": "Image captured!"})
@app.route('/post_to_instagram', methods=['POST'])
def post_to_instagram():
# Assuming you're using instabot for posting to Instagram
from instabot import Bot
bot = Bot()
bot.login(username=INSTAGRAM_USERNAME, password=INSTAGRAM_PASSWORD)
image_path = "static/images/captured_image.jpg"
bot.upload_photo(image_path, caption="Your Image Caption Here")
return jsonify({"message": "Image posted to Instagram!"})
if __name__ == '__main__':
app.run(debug=True)