Browse Source

repo init

grapemane 1 year ago
commit
8913f23056
2 changed files with 79 additions and 0 deletions
  1. 71 0
      masto.py
  2. 8 0
      stable.py

+ 71 - 0
masto.py

@@ -0,0 +1,71 @@
+from mastodon import Mastodon
+import re
+import os
+import time
+
+# Register your app! This only needs to be done once (per server, or when
+# distributing rather than hosting an application, most likely per device and server).
+# Uncomment the code and substitute in your information:
+'''
+Mastodon.create_app(
+    'grapeapp',
+    api_base_url = 'https://noc.social/',
+    to_file = 'grapeapp_clientcred.secret'
+)
+'''
+
+mastodon = Mastodon(client_id = 'grapeapp_clientcred.secret',)
+mastodon.log_in(
+    'nocsocial@teets.us',
+    'WW936dQL1H0w9zLsWvyh3Z3e1yFrE39oYoxmdARCIk8IcrBH',
+    to_file = 'grapeapp_usercred.secret'
+)
+
+
+mastodon = Mastodon(access_token = 'grapeapp_usercred.secret')
+
+mostRecentMentionRepliedTo = ''
+
+while True:
+    mostRecentMention = mastodon.notifications(types = "mention")[0].status.content
+
+    if mostRecentMention == mostRecentMentionRepliedTo:
+        time.sleep(15)
+        continue
+
+    mostRecentMentionRepliedTo = mostRecentMention
+
+    cleanTags = re.compile('<.*?>')
+    tweetWithoutTags = re.sub(cleanTags, '', mostRecentMention)
+
+    cleanMention = re.compile('@developer(@noc\.social)*')
+    tweetWithoutMention = re.sub(cleanMention, '', tweetWithoutTags)
+    
+    cleanTweet = re.sub(r'[^a-zA-Z0-9 ]', '', tweetWithoutMention)
+
+
+    rawInput = cleanTweet.strip()[:45]
+
+    print(rawInput)
+
+    os.system('python stable.py "' + rawInput + '"')
+
+    cleanSpaces = re.compile(' ')
+    folderName = re.sub(cleanSpaces, '_', rawInput)
+
+    print(folderName)
+
+
+    mentionerUrl = mastodon.notifications(types = "mention")[0].status.account.url
+    cleanProtocol = re.compile('https*:\/\/')
+    cleanedUrl = re.sub(cleanProtocol, '', mentionerUrl)
+    urlParts = cleanedUrl.split("/")
+    mentionTag = urlParts[1] + '@' + urlParts[0]
+    print(mentionTag)
+
+    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')
+
+
+    message = mentionTag + ' mentioned me and said: "' + tweetWithoutMention.strip() + '". Here\'s my dream about that!'
+
+    mastodon.status_post(status = message, media_ids = mediaId)

+ 8 - 0
stable.py

@@ -0,0 +1,8 @@
+import os
+import sys
+
+firstarg=sys.argv[1]
+
+os.chdir('C:\\Users\\bigd\\Downloads\\stable-diffusion-main\\stable-diffusion-main')
+os.system('conda activate ldm && python optimizedSD/optimized_txt2img.py --prompt "' + firstarg + '" --H 512 --W 512 --seed 28 --n_iter 1 --n_samples 1 --ddim_steps 20')
+