Advertisement
l1von

вав

Jan 2nd, 2021
17
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. if 0 < text_length <= 50 and message.from_id > 0:
  2. with open(chat_path, "a", encoding="utf8") as f:
  3. f.write(message.text + "\n")
  4.  
  5. with open(picture_path, encoding="utf8") as f:
  6. pic_count = len(f.readlines())
  7. with open(chat_path, encoding="utf8") as f:
  8. text_lines = len(f.readlines())
  9.  
  10. if text_lines >= 20 and pic_count >= 1 and text_lines % 20 == 0:
  11. print(message.from_id)
  12. print("ГЕНЕРИРУЕМ РАНДОМНО")
  13. with open(chat_path, encoding="utf8") as file:
  14. texts = file.read().splitlines()
  15. random_text = random.choice(texts)
  16. random_bottom_text = random.choice(texts) + " " + random.choice(texts)
  17. with open(picture_path, encoding="utf8") as file:
  18. pictures = file.read().splitlines()
  19. random_picture = random.choice(pictures)
  20. response = requests.get(random_picture)
  21.  
  22. random_filename = f"randomimg_{random.randint(0, 10000000000000000000000000)}.jpg"
  23. with open(random_filename, "wb") as f:
  24. f.write(response.content)
  25.  
  26. dem_filename = f"result_{random.randint(0, 10000000000000000000000000)}.jpg"
  27. random_text_len = len(random_text)
  28. if random_text_len <= 50:
  29. dem = demcreate(random_text, random_bottom_text)
  30. dem.makeImage(random_filename.rstrip(".jpg"))
  31. add_watermark_and_rename(result_filename=dem_filename)
  32. photo = await photo_uploader.upload_message_photo(dem_filename)
  33. await message(attachment=photo)
  34. os.remove(dem_filename)
  35. os.remove(random_filename)
  36. return
  37. else:
  38. random_bottom_text_short = random_text[:50]
  39. dem = demcreate(random_text, random_bottom_text_short)
  40. dem.makeImage("randomimg")
  41. add_watermark_and_rename(result_filename=dem_filename)
  42. photo = await photo_uploader.upload_message_photo(dem_filename)
  43. await message(attachment=photo)
  44. os.remove(dem_filename)
  45. os.remove(random_filename)
  46. return
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement