masto.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. from mastodon import Mastodon
  2. import re
  3. import os
  4. import time
  5. # Register your app! This only needs to be done once (per server, or when
  6. # distributing rather than hosting an application, most likely per device and server).
  7. # Uncomment the code and substitute in your information:
  8. '''
  9. Mastodon.create_app(
  10. 'grapeapp',
  11. api_base_url = 'https://noc.social/',
  12. to_file = 'grapeapp_clientcred.secret'
  13. )
  14. '''
  15. mastodon = Mastodon(client_id = 'grapeapp_clientcred.secret',)
  16. mastodon.log_in(
  17. 'nocsocial@teets.us',
  18. 'WW936dQL1H0w9zLsWvyh3Z3e1yFrE39oYoxmdARCIk8IcrBH',
  19. to_file = 'grapeapp_usercred.secret'
  20. )
  21. mastodon = Mastodon(access_token = 'grapeapp_usercred.secret')
  22. mostRecentlyHandledMention = ''
  23. while True:
  24. mostRecentMention = mastodon.notifications(types = "mention")[0]
  25. if mostRecentMention.status.content == mostRecentlyHandledMention:
  26. time.sleep(15)
  27. continue
  28. mostRecentlyHandledMention = mostRecentMention.status.content
  29. if mostRecentMention.status.in_reply_to_id != None:
  30. time.sleep(15)
  31. continue
  32. mostRecentMentionContent = mostRecentMention.status.content
  33. cleanTags = re.compile('<.*?>')
  34. tweetWithoutTags = re.sub(cleanTags, '', mostRecentMentionContent)
  35. cleanMention = re.compile('@developer(@noc\.social)*')
  36. tweetWithoutMention = re.sub(cleanMention, '', tweetWithoutTags)
  37. cleanTweet = re.sub(r'[^a-zA-Z0-9 ]', '', tweetWithoutMention)
  38. rawInput = cleanTweet.strip()[:45]
  39. print(rawInput)
  40. os.system('python stable.py "' + rawInput + '"')
  41. cleanSpaces = re.compile(' ')
  42. folderName = re.sub(cleanSpaces, '_', rawInput)
  43. print(folderName)
  44. mentionerTag = '@' + mostRecentMention.status.account.acct
  45. print(mentionerTag)
  46. mediaId = mastodon.media_post(media_file = 'C:\\Users\\bigd\\Downloads\\stable-diffusion-main\\stable-diffusion-main\\outputs\\txt2img-samples\\' + folderName + '\\seed_28_00000.png', mime_type = 'image/png')
  47. message = mentionerTag + ' mentioned me and said: "' + tweetWithoutMention.strip() + '". Here\'s my dream about that!'
  48. mastodon.status_post(in_reply_to_id = mostRecentMention.status, status = message, media_ids = mediaId)