masto.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. mostRecentMentionRepliedTo = ''
  23. while True:
  24. mostRecentMention = mastodon.notifications(types = "mention")[0].status.content
  25. if mostRecentMention == mostRecentMentionRepliedTo:
  26. time.sleep(15)
  27. continue
  28. mostRecentMentionRepliedTo = mostRecentMention
  29. cleanTags = re.compile('<.*?>')
  30. tweetWithoutTags = re.sub(cleanTags, '', mostRecentMention)
  31. cleanMention = re.compile('@developer(@noc\.social)*')
  32. tweetWithoutMention = re.sub(cleanMention, '', tweetWithoutTags)
  33. cleanTweet = re.sub(r'[^a-zA-Z0-9 ]', '', tweetWithoutMention)
  34. rawInput = cleanTweet.strip()[:45]
  35. print(rawInput)
  36. os.system('python stable.py "' + rawInput + '"')
  37. cleanSpaces = re.compile(' ')
  38. folderName = re.sub(cleanSpaces, '_', rawInput)
  39. print(folderName)
  40. mentionerUrl = mastodon.notifications(types = "mention")[0].status.account.url
  41. cleanProtocol = re.compile('https*:\/\/')
  42. cleanedUrl = re.sub(cleanProtocol, '', mentionerUrl)
  43. urlParts = cleanedUrl.split("/")
  44. mentionTag = urlParts[1] + '@' + urlParts[0]
  45. print(mentionTag)
  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 = mentionTag + ' mentioned me and said: "' + tweetWithoutMention.strip() + '". Here\'s my dream about that!'
  48. mastodon.status_post(status = message, media_ids = mediaId)