diff --git a/Discord/bot.py b/Discord/bot.py index 1ef771a1..6a260ff3 100644 --- a/Discord/bot.py +++ b/Discord/bot.py @@ -17,7 +17,7 @@ import textwrap import os from Lists.img_list import PHILOSOPHERS_LIST -from Templates.New_Img_Manipulation.reference import TEMPLATES_PATH +from Templates.New_Img_Manipulation.path_reference import TEMPLATES_PATH # loads .env dotenv.load_dotenv(dotenv.find_dotenv()) @@ -182,7 +182,7 @@ async def clear(ctx, numero): @client.command() # função principal async def philobot(ctx, *, mensagem): try: - img = Image.open(f'{TEMPLATES_PATH}/layer_1.png') + img = Image.open(f'{TEMPLATES_PATH}/background_image.png') font = ImageFont.truetype(os.getenv('myriad_font'), 50) drawing = ImageDraw.Draw(img) diff --git a/Font/OpenSansEmoji.ttf b/Font/OpenSansEmoji.ttf new file mode 100644 index 00000000..57d86a62 Binary files /dev/null and b/Font/OpenSansEmoji.ttf differ diff --git a/Font/twitterchirp.ttf b/Font/twitterchirp.ttf new file mode 100644 index 00000000..6dcbf36a Binary files /dev/null and b/Font/twitterchirp.ttf differ diff --git a/Templates/New_Img_Manipulation/__pycache__/path_reference.cpython-39.pyc b/Templates/New_Img_Manipulation/__pycache__/path_reference.cpython-39.pyc new file mode 100644 index 00000000..c857e059 Binary files /dev/null and b/Templates/New_Img_Manipulation/__pycache__/path_reference.cpython-39.pyc differ diff --git a/Templates/New_Img_Manipulation/__pycache__/reference.cpython-38.pyc b/Templates/New_Img_Manipulation/__pycache__/reference.cpython-38.pyc deleted file mode 100644 index 62ca4b8a..00000000 Binary files a/Templates/New_Img_Manipulation/__pycache__/reference.cpython-38.pyc and /dev/null differ diff --git a/Templates/New_Img_Manipulation/__pycache__/reference.cpython-39.pyc b/Templates/New_Img_Manipulation/__pycache__/reference.cpython-39.pyc deleted file mode 100644 index cb8e4ee4..00000000 Binary files a/Templates/New_Img_Manipulation/__pycache__/reference.cpython-39.pyc and /dev/null differ diff --git a/Templates/New_Img_Manipulation/layer_1.png b/Templates/New_Img_Manipulation/background_image.png similarity index 100% rename from Templates/New_Img_Manipulation/layer_1.png rename to Templates/New_Img_Manipulation/background_image.png diff --git a/Templates/New_Img_Manipulation/path_reference.py b/Templates/New_Img_Manipulation/path_reference.py new file mode 100644 index 00000000..ffd5aca7 --- /dev/null +++ b/Templates/New_Img_Manipulation/path_reference.py @@ -0,0 +1,3 @@ +import os + +template_folder_reference = os.path.dirname(os.path.abspath(__file__)) diff --git a/Templates/New_Img_Manipulation/reference.py b/Templates/New_Img_Manipulation/reference.py deleted file mode 100644 index 24b0203a..00000000 --- a/Templates/New_Img_Manipulation/reference.py +++ /dev/null @@ -1,3 +0,0 @@ -import os - -TEMPLATES_PATH = os.path.dirname(os.path.abspath(__file__)) diff --git a/Templates/New_Img_Manipulation/layer_3.png b/Templates/New_Img_Manipulation/smooth_background.png similarity index 100% rename from Templates/New_Img_Manipulation/layer_3.png rename to Templates/New_Img_Manipulation/smooth_background.png diff --git a/Test/ipre_final_test.png b/Test/ipre_final_test.png new file mode 100644 index 00000000..8bbee0a4 Binary files /dev/null and b/Test/ipre_final_test.png differ diff --git a/Text/new_img_treatment/img.py b/Text/new_img_treatment/img.py index 3fa21ff9..e74f20f7 100644 --- a/Text/new_img_treatment/img.py +++ b/Text/new_img_treatment/img.py @@ -5,7 +5,7 @@ import tweepy import os from Credentials.Twitter.Test import API_MAIN_TEST -from Templates.New_Img_Manipulation.reference import TEMPLATES_PATH +from Templates.New_Img_Manipulation.path_reference import TEMPLATES_PATH api = API_MAIN_TEST diff --git a/Twitter/Hashtag/philobot_engine.py b/Twitter/Hashtag/philobot_engine.py index 8160d45d..6a6d320e 100644 --- a/Twitter/Hashtag/philobot_engine.py +++ b/Twitter/Hashtag/philobot_engine.py @@ -4,7 +4,7 @@ from PIL import Image, ImageFont from Twitter.Hashtag.functionalities import Functionalities from Lists.img_list import PHILOSOPHERS_LIST -from Templates.New_Img_Manipulation.reference import TEMPLATES_PATH +from Templates.New_Img_Manipulation.path_reference import TEMPLATES_PATH # from Logs.Twitter.log_engine import log_hashtag diff --git a/Twitter/Hashtag/philomaker_engine.py b/Twitter/Hashtag/philomaker_engine.py index 91ff2dee..91255772 100644 --- a/Twitter/Hashtag/philomaker_engine.py +++ b/Twitter/Hashtag/philomaker_engine.py @@ -5,7 +5,7 @@ from urllib import request from PIL import Image, ImageFont from Lists.error_img_list import PHILOMAKER_ERROR_IMAGE_COLLECTION -from Templates.New_Img_Manipulation.reference import TEMPLATES_PATH +from Templates.New_Img_Manipulation.path_reference import TEMPLATES_PATH from Logs.Twitter.logger_hashtag import log_hashtag import os from Twitter.Hashtag.functionalities import Functionalities diff --git a/Twitter/Posting/new_posting.py b/Twitter/Posting/new_posting.py index 35073d0b..17a925e5 100644 --- a/Twitter/Posting/new_posting.py +++ b/Twitter/Posting/new_posting.py @@ -1,34 +1,178 @@ -import schedule, time, os, random, tweepy -from PIL import Image, ImageFont +import schedule, time, os, random, tweepy, re, textwrap, datetime, demoji +import emoji +from PIL import Image, ImageFont, ImageDraw from Lists.accounts import accounts_list from Lists.img_list import PHILOSOPHERS_LIST from Credentials.Twitter.Test.test_credentials import API_TEST +from Templates.New_Img_Manipulation.path_reference import template_folder_reference +from Twitter.Posting.uploads.path_reference import upload_folder_reference +from dotenv import load_dotenv class PostingClass: def __init__(self): - self.FONT_PATH = os.getenv('myriad_font') + load_dotenv() + + self.uploads_path = upload_folder_reference + + self.date_today = datetime.datetime.now().strftime('%Y%m%d') + self.time_now = datetime.datetime.now().strftime('%H-%M-%S') + + self.posting_image_name = self.time_now + '_posting.png' + self.finish_image = fr"{self.uploads_path}\{self.date_today}\{self.posting_image_name}" + + self.philosopher_path = random.choice(PHILOSOPHERS_LIST) + self.philosopher_name_raw = os.path.basename(self.philosopher_path).replace('.png', '') + self.philosopher_name = self.clear_philosopher_name() + self.tweet_text = None + self.tweet_id = None self.api = API_TEST - pass + self.philosopher_data = {} + self.name_font_path = r'C:\Users\rodri\Documents\GitHub\The-Philosopher-BOT\Font\times.ttf' + self.text_font_path = r'C:\Users\rodri\Documents\GitHub\The-Philosopher-BOT\Font\OpenSansEmoji.ttf' + + def start_posting(self): + # 1 - coletar o texto de algum tweet + self.create_uploads_folder() + + self.tweet_text = self.select_tweet() + + self.emoji_check() + + breakpoint() + + print(self.tweet_text) + get_unicode = self.tweet_text.encode('unicode-escape').decode('ASCII') + print(get_unicode) + + self.text_setting(raw_image=self.build_image()) + + self.upload_image() + + def create_uploads_folder(self): + try: + self.uploads_path = self.uploads_path + '/' + os.mkdir(self.uploads_path + self.date_today) + print('CRIADO!') + + except FileExistsError: + print('Arquivo ja existe') + + except Exception as create_uploads_folder_err: + print(create_uploads_folder_err) + + def get_tweet(self): + tweet_data = self.api.user_timeline(screen_name='syscat_13', + count=1, + tweet_mode='extended', + contributor_details=True, + include_entities=True, + include_rts=False, + trim_user=True, + exclude_replies=True) + + for tweet in tweet_data: + self.tweet_text = re.sub(r'http\S+', '', tweet.full_text).replace('\n', ' ') + self.tweet_id = tweet.id + time.sleep(2) + + def select_tweet(self): + while True: + self.get_tweet() + + if self.tweet_text: + return self.tweet_text + + # time.sleep(10) + # implementar funcionalidade de mudar de conta escolhida caso o tweet venha em branco + + def emoji_check(self): + if emoji.emoji_count(self.tweet_text) > 0: + print(emoji.demojize(self.tweet_text)) + + + + + + + + + + + + + + + + def select_name_font(self): + if len(self.philosopher_name) <= 20: + return ImageFont.truetype(self.name_font_path, size=35) + + else: + return ImageFont.truetype(self.name_font_path, size=30) + + def select_text_font(self): + if len(self.tweet_text) <= 140: + wrapper_limit = 21 + print('menos que 140') + return [ImageFont.truetype(self.text_font_path, size=45), wrapper_limit] + + else: + wrapper_limit = 30 + return [ImageFont.truetype(self.text_font_path, size=32), wrapper_limit] + + def text_setting(self, raw_image): + text_adjust = self.select_text_font() + + raw_image_draw = ImageDraw.Draw(raw_image) + + raw_image_draw.text(xy=(43, 500), text=textwrap.fill(str('- ' + self.philosopher_name), 30), + fill=(255, 255, 255), font=self.select_name_font()) + + print(self.tweet_text) + # breakpoint() + # raw_image_draw.text(xy=(68, 120), text=textwrap.fill(self.tweet_text, text_adjust[1]), fill=(255, 255, 255), + # font=text_adjust[0]) + + raw_image_draw.text(xy=(68, 120), text=self.tweet_text, fill=(255, 255, 255), + font=text_adjust[0]) + + raw_image.save(self.finish_image) + + def clear_philosopher_name(self): + if '(2)' in self.philosopher_name_raw: + return self.philosopher_name_raw.replace('(2)', '') + + else: + return self.philosopher_name_raw + + def build_image(self): + raw_image = Image.open(f'{template_folder_reference}/background_image.png') + + philosopher_image = Image.open(self.philosopher_path).resize((449, 584)) + raw_image.paste(philosopher_image, (629, 0)) + + smooth_template = Image.open(f'{template_folder_reference}/smooth_background.png') + raw_image.paste(smooth_template, (0, 0), smooth_template) + + # build_image.save(r'C:\Users\rodri\Documents\GitHub\The-Philosopher-BOT\Test\image_smooth_test.png') + + return raw_image - def get_tweets(self): - return self.api.user_timeline(screen_name='rodrigoblock4', - count=1, - tweet_mode='extended', - contributor_details=True, - include_entities=True, - include_rts=False, - trim_user=True, - exclude_replies=True) + def upload_image(self): + try: + upload_image = self.api.update_with_media(self.finish_image) - def post_engine(self): - # new_image = Image.new('RGB', (269, 194)) - # font = ImageFont.truetype(self.FONT_PATH, 1) - v1 = random.choice(PHILOSOPHERS_LIST) - v2 = os.path.basename(v1).replace('.png', '') + tweet_author = self.api.update_status( + f'Tweet original: twitter.com/syscat_13/status/{self.tweet_id}', + upload_image.id, + include_entities=True) + except Exception as upload_err: + print('error') + print(upload_err) - print(v2) + print('Tweet enviado!') def start_timer_test(self): schedule.every(2).seconds.do(self.post_engine) @@ -42,4 +186,5 @@ def select_account(): if __name__ == '__main__': - PostingClass().post_engine() + p = PostingClass() + p.start_posting() diff --git a/Twitter/Posting/posting.py b/Twitter/Posting/posting.py index 472fcaa1..96c48711 100644 --- a/Twitter/Posting/posting.py +++ b/Twitter/Posting/posting.py @@ -14,7 +14,7 @@ from PIL import Image, ImageDraw, ImageFont from Lists.accounts import accounts_list from Lists.img_list import PHILOSOPHERS_LIST -from Templates.New_Img_Manipulation.reference import TEMPLATES_PATH +from Templates.New_Img_Manipulation.path_reference import TEMPLATES_PATH dotenv.load_dotenv(dotenv.find_dotenv()) diff --git a/Twitter/Posting/uploads/20220115/18-30-46_posting.png b/Twitter/Posting/uploads/20220115/18-30-46_posting.png new file mode 100644 index 00000000..c0fcca70 Binary files /dev/null and b/Twitter/Posting/uploads/20220115/18-30-46_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/18-34-55_posting.png b/Twitter/Posting/uploads/20220115/18-34-55_posting.png new file mode 100644 index 00000000..a072009b Binary files /dev/null and b/Twitter/Posting/uploads/20220115/18-34-55_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/19-01-16_posting.png b/Twitter/Posting/uploads/20220115/19-01-16_posting.png new file mode 100644 index 00000000..118835e2 Binary files /dev/null and b/Twitter/Posting/uploads/20220115/19-01-16_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/19-02-44_posting.png b/Twitter/Posting/uploads/20220115/19-02-44_posting.png new file mode 100644 index 00000000..eb421dae Binary files /dev/null and b/Twitter/Posting/uploads/20220115/19-02-44_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/19-08-08_posting.png b/Twitter/Posting/uploads/20220115/19-08-08_posting.png new file mode 100644 index 00000000..528d3e02 Binary files /dev/null and b/Twitter/Posting/uploads/20220115/19-08-08_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/19-11-16_posting.png b/Twitter/Posting/uploads/20220115/19-11-16_posting.png new file mode 100644 index 00000000..3122318e Binary files /dev/null and b/Twitter/Posting/uploads/20220115/19-11-16_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/19-11-57_posting.png b/Twitter/Posting/uploads/20220115/19-11-57_posting.png new file mode 100644 index 00000000..44c3057b Binary files /dev/null and b/Twitter/Posting/uploads/20220115/19-11-57_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/19-51-27_posting.png b/Twitter/Posting/uploads/20220115/19-51-27_posting.png new file mode 100644 index 00000000..395753cc Binary files /dev/null and b/Twitter/Posting/uploads/20220115/19-51-27_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/20-07-32_posting.png b/Twitter/Posting/uploads/20220115/20-07-32_posting.png new file mode 100644 index 00000000..546a9356 Binary files /dev/null and b/Twitter/Posting/uploads/20220115/20-07-32_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/20-10-03_posting.png b/Twitter/Posting/uploads/20220115/20-10-03_posting.png new file mode 100644 index 00000000..89e63ebc Binary files /dev/null and b/Twitter/Posting/uploads/20220115/20-10-03_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/20-10-37_posting.png b/Twitter/Posting/uploads/20220115/20-10-37_posting.png new file mode 100644 index 00000000..b5615cd5 Binary files /dev/null and b/Twitter/Posting/uploads/20220115/20-10-37_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/20-11-10_posting.png b/Twitter/Posting/uploads/20220115/20-11-10_posting.png new file mode 100644 index 00000000..0c6bb798 Binary files /dev/null and b/Twitter/Posting/uploads/20220115/20-11-10_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/20-11-48_posting.png b/Twitter/Posting/uploads/20220115/20-11-48_posting.png new file mode 100644 index 00000000..c4f69925 Binary files /dev/null and b/Twitter/Posting/uploads/20220115/20-11-48_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/20-13-14_posting.png b/Twitter/Posting/uploads/20220115/20-13-14_posting.png new file mode 100644 index 00000000..6b786702 Binary files /dev/null and b/Twitter/Posting/uploads/20220115/20-13-14_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/20-15-28_posting.png b/Twitter/Posting/uploads/20220115/20-15-28_posting.png new file mode 100644 index 00000000..39584872 Binary files /dev/null and b/Twitter/Posting/uploads/20220115/20-15-28_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/20-16-00_posting.png b/Twitter/Posting/uploads/20220115/20-16-00_posting.png new file mode 100644 index 00000000..0e71b754 Binary files /dev/null and b/Twitter/Posting/uploads/20220115/20-16-00_posting.png differ diff --git a/Twitter/Posting/uploads/20220115/20-23-54_posting.png b/Twitter/Posting/uploads/20220115/20-23-54_posting.png new file mode 100644 index 00000000..db2731d3 Binary files /dev/null and b/Twitter/Posting/uploads/20220115/20-23-54_posting.png differ diff --git a/Twitter/Posting/uploads/__pycache__/path_reference.cpython-39.pyc b/Twitter/Posting/uploads/__pycache__/path_reference.cpython-39.pyc new file mode 100644 index 00000000..6fced142 Binary files /dev/null and b/Twitter/Posting/uploads/__pycache__/path_reference.cpython-39.pyc differ diff --git a/Twitter/Posting/uploads/path_reference.py b/Twitter/Posting/uploads/path_reference.py new file mode 100644 index 00000000..a072118c --- /dev/null +++ b/Twitter/Posting/uploads/path_reference.py @@ -0,0 +1,3 @@ +import os + +upload_folder_reference = os.path.dirname(os.path.abspath(__file__)) diff --git a/teste.py b/teste.py new file mode 100644 index 00000000..e3802461 --- /dev/null +++ b/teste.py @@ -0,0 +1,9 @@ +emoji_folder = r'C:\Users\rodri\Documents\The-Philosopher-BOT-2.5.3\TWITTER\v2.5.2\Emojis' +import os + +files = os.listdir(emoji_folder) + +# print(u'\U0001f603') +for e in files: + new_e = e.replace('.png', '') + print("\" + ffU000{new_e})