-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
133 lines (109 loc) · 4.16 KB
/
Copy pathapp.py
File metadata and controls
133 lines (109 loc) · 4.16 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
'''import openai
from PIL import Image, ImageDraw, ImageFont
from instabot import Bot
import time
import os
# OpenAI API key
openai.api_key = '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'
def generate_coding_question(prompt, temperature=0.7, max_tokens=100):
try:
response = openai.Completion.create(
engine="text-davinci-004",
prompt=prompt,
temperature=temperature,
max_tokens=max_tokens
)
return response.choices[0].text.strip()
except Exception as e:
print(f"Error generating question: {e}")
return None
def create_social_media_image(question, filename="coding_question.png"):
# Image dimensions and colors
width, height = 800, 400
background_color = (255, 255, 255) # White background
text_color = (0, 0, 0) # Black text
# Create an image with a specific background color
img = Image.new('RGB', (width, height), color=background_color)
d = ImageDraw.Draw(img)
# Load a custom font
try:
font = ImageFont.truetype("Lemon-Regular.ttf", 20)
except IOError:
font = ImageFont.load_default()
print("Custom font not found. Using default font.")
# Add text to the image
d.text((20, 50), question, fill=text_color, font=font)
#Optionally add your logo or other elements
logo = Image.open("logo.png")
img.paste(logo, (650, 300), logo)
# Save the image
img.save(filename)
# Login to Instagram
#bot = Bot()
#bot.login(username="algorithm.arena", password="#####")
while True:
question = generate_coding_question("Create a unique and interesting coding question in python for a computer science student at an easy to medium difficulty level:")
if question:
image_filename = "coding_question.png"
create_social_media_image(question, image_filename)
#bot.upload_photo(image_filename, caption=question)
#if bot.api.last_response.status_code != 200:
#print("Error uploading photo.")
# Wait for 24 hours
time.sleep(86400) # 86400 seconds in a day'''
import openai
from PIL import Image, ImageDraw, ImageFont
from instabot import Bot
import os
import textwrap
# Load OpenAI API key from an environment variable
client = openai()
def generate_coding_question(prompt, temperature=0.7, max_tokens=100):
try:
response = client.chat.completions.create(
engine="text-davinci-004",
prompt=prompt,
temperature=temperature,
max_tokens=max_tokens
)
return response.choices[0].text.strip()
except Exception as e:
print(f"Error generating question: {e}")
return None
def create_social_media_image(question, filename="coding_question.png"):
# Image dimensions and colors
width, height = 800, 400
background_color = (255, 69, 0) # Reddish orange background
text_color = (0, 0, 0) # Black text
# Create an image with a specific background color
img = Image.new('RGB', (width, height), color=background_color)
d = ImageDraw.Draw(img)
# Load a custom font
try:
font = ImageFont.truetype("Lemon-Regular.ttf", 20)
except IOError:
font = ImageFont.load_default()
print("Custom font not found. Using default font.")
# Wrap text
wrapped_text = textwrap.fill(question, width=70)
# Add text to the image
d.text((20, 50), wrapped_text, fill=text_color, font=font)
# Optionally add your logo or other elements
try:
logo = Image.open("logo.png")
img.paste(logo, (650, 300), logo)
except IOError:
print("Logo file not found.")
# Save the image
img.save(filename)
def post_to_instagram(filename):
# Placeholder for Instabot code to post the image
# bot = Bot()
# bot.login(username='your_username', password='your_password')
# bot.upload_photo(filename, caption='Here is a coding question!')
pass
# Example usage
question = generate_coding_question("Create a unique and interesting coding question in python for a computer science student at an easy to medium difficulty level:")
if question:
create_social_media_image(question)
# post_to_instagram("coding_question.png")