Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,39 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, render_template, request, jsonify
|
2 |
+
import os
|
3 |
+
import cv2
|
4 |
+
import base64
|
5 |
+
import requests
|
6 |
+
|
7 |
+
app = Flask(__name__)
|
8 |
+
|
9 |
+
# Instagram credentials (use your Instagram bot or automation method here)
|
10 |
+
INSTAGRAM_USERNAME = 'your_username'
|
11 |
+
INSTAGRAM_PASSWORD = 'your_password'
|
12 |
+
|
13 |
+
@app.route('/')
|
14 |
+
def index():
|
15 |
+
return render_template('index.html')
|
16 |
+
|
17 |
+
@app.route('/capture', methods=['POST'])
|
18 |
+
def capture():
|
19 |
+
image_data = request.form['image']
|
20 |
+
# Decode the image from base64 to save it
|
21 |
+
img_data = base64.b64decode(image_data.split(',')[1])
|
22 |
+
with open("static/images/captured_image.jpg", "wb") as f:
|
23 |
+
f.write(img_data)
|
24 |
+
|
25 |
+
return jsonify({"message": "Image captured!"})
|
26 |
+
|
27 |
+
@app.route('/post_to_instagram', methods=['POST'])
|
28 |
+
def post_to_instagram():
|
29 |
+
# Assuming you're using instabot for posting to Instagram
|
30 |
+
from instabot import Bot
|
31 |
+
bot = Bot()
|
32 |
+
bot.login(username=INSTAGRAM_USERNAME, password=INSTAGRAM_PASSWORD)
|
33 |
+
image_path = "static/images/captured_image.jpg"
|
34 |
+
bot.upload_photo(image_path, caption="Your Image Caption Here")
|
35 |
+
|
36 |
+
return jsonify({"message": "Image posted to Instagram!"})
|
37 |
+
|
38 |
+
if __name__ == '__main__':
|
39 |
+
app.run(debug=True)
|