-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
181 lines (138 loc) · 5.27 KB
/
main.py
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
import difflib
import random
import os
import time
from PIL import Image
from PIL import ImageDraw
from PIL import ImageFont
from instagrapi import Client
# Mengecek Quotes
def delete_similar_quotes(file_path):
with open(file_path, 'r') as f:
quotes = f.readlines()
deleted_count = 0
for i in range(len(quotes)):
for j in range(i+1, len(quotes)):
seq = difflib.SequenceMatcher(None, quotes[i], quotes[j])
ratio = seq.ratio()
if ratio > 0.7 and ratio < 0.99:
if len(quotes[i]) > len(quotes[j]):
del quotes[i]
else:
del quotes[j]
deleted_count += 1
break
with open(file_path, 'w') as f:
f.writelines(quotes)
if deleted_count > 0:
print(f"{deleted_count} quotes yang mirip telah dihapus.")
else:
print("Tidak ada quotes yang mirip dihapus.")
delete_similar_quotes('quotes/sedih.txt')
time.sleep(2)
# Memilih 1 Quote
def move_random_quote(source_file_path, target_file_path):
# Read quotes from source file
with open(source_file_path, 'r') as f:
quotes = f.readlines()
# Choose a random quote
random_index = random.randrange(len(quotes))
random_quote = quotes[random_index]
# Write the random quote to the target file
with open(target_file_path, 'a') as f:
f.write(random_quote)
# Remove the random quote from the source file
with open(source_file_path, 'w') as f:
quotes.pop(random_index)
f.writelines(quotes)
print(f"Quote acak telah dipindahkan ke {target_file_path} dan dihapus dari {source_file_path}.")
move_random_quote('quotes/sedih.txt', 'quotes/edit.txt')
time.sleep(2)
# Memberikan Random New Line "\n"
def add_random_newline(file_path, n=2):
# Read the content of the file
with open(file_path, 'r') as f:
content = f.read()
# Add random newline characters to a random sentence
sentences = content.split('. ')
random_sentence_index = random.randrange(len(sentences))
sentence = sentences[random_sentence_index].strip()
# Split the sentence into words
words = sentence.split(' ')
# Add newline characters randomly to the sentence
new_sentence = ''
for i, word in enumerate(words):
new_sentence += word
if i < len(words) - 3 and random.random() < 0.4:
new_sentence += '\n'
else:
new_sentence += ' '
# Print the original and modified sentences
print(f'Original sentence: {sentence}')
print(f'Modified sentence: {new_sentence}\n')
# Write the modified content to the file
with open(file_path, 'w') as f:
content = content.replace(sentence, new_sentence, 1)
f.write(content)
add_random_newline('quotes/edit.txt')
time.sleep(2)
#Mengedit Gambar
# Membuka file gambar base.jpg
img = Image.open('images/base.jpg')
# Membuat objek ImageDraw untuk menggambar pada gambar
draw = ImageDraw.Draw(img)
# Mendapatkan ukuran gambar
width, height = img.size
# Membuat objek font Helvetica dengan ukuran 50
font = ImageFont.truetype("font/Helvetica.ttf", 40)
# Membuka file /quotes/edit.txt dan membaca teks dari file
with open('quotes/edit.txt', 'r') as f:
text = f.read() #.replace('\n', '') # Menghapus karakter newline jika ada
# Mendapatkan ukuran teks
text_width, text_height = draw.textsize(text, font)
# Menghitung posisi X dan Y untuk menempatkan teks di tengah gambar
x = (width - text_width) / 2
y = (height - text_height) / 2
# Menambahkan teks ke dalam gambar pada posisi yang telah dihitung dan dengan warna hitam
draw.text((x, y), text, font=font, fill=(0,0,0))
# Menyimpan gambar
img.save('images/hasil.jpg')
print("Foto Berhasil Diedit!")
time.sleep(2)
# Mengupload Quotes
# Baca file acc.txt dan ambil nilai username dan password
with open("account/acc.txt", "r") as f:
lines = f.readlines()
username = lines[0].split(" = ")[1].strip().strip('"')
password = lines[1].split(" = ")[1].strip().strip('"')
# Buat instance Client
client = Client()
# Login dengan username dan password
client.login(username, password)
# Masukkan caption dan path gambar yang akan diupload
caption = '''
Dibuat otomatis oleh AI.
.
.
.
.
Tags:
#writer #writing #quotes #quotesindonesia #quotesislami
#quotesgalau #quote #quoteoftheday #quotestagram #quotesdaily
#senja #literasi30detik #literasi #literasi15detik #galau
#galauquotes #katakatabijak #katakatamotivasi #katakatacinta
#katabijak #katakata #katamutiara #katamotivasi #sajak #sajakcinta
#sajakrindu #sajakdetik #puisi #puisicinta
'''
image_path = "images/hasil.jpg"
# Buka file gambar
with open(image_path, "rb") as f:
# upload photo
client.photo_upload(str(image_path), caption=caption)
print("Upload Berhasil!")
# Keluar dari akun
client.logout()
#Menghapus Quote
with open('quotes/edit.txt', 'w') as f:
f.write('')
print("Semua Proses Telah Selesai!")