-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj2.py
More file actions
922 lines (831 loc) · 32.2 KB
/
Copy pathboj2.py
File metadata and controls
922 lines (831 loc) · 32.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
import sys
import random
from openai import OpenAI
from slack_sdk.webhook import WebhookClient
from slack_sdk.errors import SlackApiError
import requests
import subprocess
import base64
from urlextract import URLExtract
import keys
# Define constants for better readability
HOME_DIR = keys.home_dir
IMG_PATH = keys.img_path
OPENAI_API_KEY = keys.openai_api_key
# Slack webhook URLs
SLACK_AI_KEY = keys.slack_ai_key
SLACK_DEV_KEY = keys.slack_dev_key
client = OpenAI(api_key=OPENAI_API_KEY)
# Content Styles
CONTENT_STYLES = {
1: "Verses",
2: "Psalm",
3: "Proverbial Selections",
4: "Parable",
5: "Poetic Addendum",
6: "John's Jests"
}
def get_webhook_client(is_dev_mode):
"""
Returns the appropriate WebhookClient based on the development mode flag.
Args:
is_dev_mode (bool): True if in development mode, False otherwise.
Returns:
WebhookClient: The Slack WebhookClient instance.
"""
if is_dev_mode:
return WebhookClient(f"https://hooks.slack.com/services/{SLACK_DEV_KEY}")
else:
return WebhookClient(f"https://hooks.slack.com/services/{SLACK_AI_KEY}")
def get_gpt_prompt(content_style, theme, activity_data, bro_gpt_text, number_verses, starting_verse_number):
"""
Generates the prompt for ChatGPT.
Args:
content_style (int): The selected content style (1-6).
theme (str): The selected theme for the story.
activity_data (dict): The chosen activity data.
bro_gpt_text (str): Text related to the bro, if applicable.
number_verses (int): The number of verses in the story.
starting_verse_number (int): The starting verse number.
Returns:
str: The GPT prompt.
"""
if content_style == 1: # Book/Chapter
return (
f"You are the greatest storyteller in the world. Tell me a descriptive story about John. "
f"John loves to drink and loves to gamble. Tell me about when John was "
f"{activity_data['activity']}{bro_gpt_text} "
f"with the theme of {theme}. "
f"Make sure to incorporate a cocktail which should be in theme with the story, "
f"but do not give the cocktail a name. "
f"Use exactly {number_verses} sentences. "
f"Number each sentence, starting with {starting_verse_number}. "
f"Add a new line after each sentence. "
f"For example, {starting_verse_number}: Your first sentence goes here.\n\n"
)
elif content_style == 2: # Psalms (Song Lyrics)
return (
f"Write a song about John experiencing {theme} while {activity_data['activity']}{bro_gpt_text}. "
f"Incorporate a cocktail inspired by the theme but do not give the cocktail a name. "
f"Choose from a number of different music styles like heavy metal, rap, 80 pop, classic rock, or something fun."
f"Use no more than 150 words."
)
elif content_style == 3: # Proverbs (One-Sentence Examples)
return (
f"Give me 3 short, insightful proverbs about John's experiences with {theme} "
f"while {activity_data['activity']}{bro_gpt_text}. "
f"Each proverb should be a single, impactful sentence, in quotes. "
f"Tie the proverbs together in a short story using a religious tone. "
f"Do not number the sentences and put two new lines between each quote."
)
elif content_style == 4: # Parables (Short Story with Moral)
return (
f"Tell me a short parable about John's experiences with {theme} while {activity_data['activity']}{bro_gpt_text}. "
f"The parable should have a clear moral or lesson and be extremely formal. "
f"Use no more than 150 words."
)
elif content_style == 5: # Poem
return (
f"Write a poem about John experiencing {theme} while {activity_data['activity']}{bro_gpt_text}. "
f"Incorporate a cocktail inspired by the theme but do not give the cocktail a name. "
f"The poem should have a poetic and reflective tone. Pick a poet to emulate but do not tell me who."
f"Use no more than 50 words."
)
elif content_style == 6: # Quips/Jokes
return (
f"Tell me a dirty joke about John's experiences with {theme} "
f"while {activity_data['activity']}{bro_gpt_text} in the style of stand up comedy. "
f"Use no more than 150 words. Do not preface the joke, just tell it."
)
else:
raise ValueError("Invalid content style. Please select a style between 1 and 6.")
def generate_gpt_story(prompt, content_style):
"""
Generates a story using the OpenAI GPT API.
Args:
prompt (str): The prompt for ChatGPT.
content_style (int): The selected content style (1-6).
Returns:
str: The generated story.
"""
if content_style == 1: # Book/Chapter
response = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[
{"role": "system", "content": "You are the most prolific story teller of all time. "
"You always leave your readers astonished, bewildered, intrigued, or some other strong emotion."},
{"role": "user", "content": prompt}
],
temperature=1
)
return response.choices[0].message.content
elif content_style == 2: # Psalms (Song Lyrics)
response = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[
{"role": "system", "content": "You are a skilled poet and lyricist."},
{"role": "user", "content": prompt}
],
temperature=1 # Lower temperature for more structured output
)
return response.choices[0].message.content
elif content_style == 3: # Proverbs (One-Sentence Examples)
response = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[
{"role": "system", "content": "You are a wise sage who can craft insightful proverbs."},
{"role": "user", "content": prompt}
],
temperature=1
)
return response.choices[0].message.content
elif content_style == 4: # Parables (Short Story with Moral)
response = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[
{"role": "system", "content": "You are a master storyteller who can weave captivating parables."},
{"role": "user", "content": prompt}
],
temperature=1
)
return response.choices[0].message.content
elif content_style == 5: # Poem
response = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[
{"role": "system", "content": "You are a skilled poet."},
{"role": "user", "content": prompt}
],
temperature=1
)
return response.choices[0].message.content
elif content_style == 6: # Quips/Jokes
response = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[
{"role": "system", "content": "You are a witty comedian and a wise guy."},
{"role": "user", "content": prompt}
],
temperature=1
)
return "\n".join(response.choices[0].message.content.split("\n"))
else:
raise ValueError("Invalid content style.")
def generate_dalle_prompt(story, bro_dalle_text, content_style):
"""
Generates a concise DALL-E prompt using GPT-4.
Args:
story (str): The generated story from GPT.
bro_dalle_text (str): Text related to the bro for DALL-E, if applicable.
content_style (int): The selected content style (1-6).
Returns:
str: The DALL-E prompt, or None if no image is to be generated.
"""
if content_style in [1, 4]: # Chronicles, Parables (more visual narratives)
response = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[
{"role": "system", "content": "You are an expert image prompt engineer. "
"Your task is to create a concise and evocative DALL-E prompt "
"based on the provided text, suitable for generating a high-quality image. "
"Incorporate character descriptions where relevant."},
{"role": "user", "content": f"Generate a DALL-E prompt, less than 100 words, for an image that visually represents: {story} {bro_dalle_text}"}
],
temperature=0.7,
)
return response.choices[0].message.content
elif content_style in [2, 5]: # Psalms, Verses (more abstract, mood-based)
response = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[
{"role": "system", "content": "You are an expert image prompt engineer. "
"Your task is to create a concise and evocative DALL-E prompt "
"based on the provided text, suitable for generating an abstract or symbolic image."},
{"role": "user", "content": f"Generate a DALL-E prompt, less than 100 words, for an image that visually represents the mood and themes of: {story} {bro_dalle_text}"}
],
temperature=0.7,
)
return response.choices[0].message.content
elif content_style == 3: # Proverbs (focus on core message)
response = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[
{"role": "system", "content": "You are an expert image prompt engineer. "
"Your task is to create a concise and evocative DALL-E prompt "
"that visually represents the core message of the proverb."},
{"role": "user", "content": f"Generate a DALL-E prompt, less than 100 words, for an image that illustrates: {story} {bro_dalle_text}"}
],
temperature=0.7,
)
return response.choices[0].message.content
elif content_style == 6: # Jests (humor and exaggeration)
response = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[
{"role": "system", "content": "You are an expert image prompt engineer. "
"Your task is to create a concise and evocative DALL-E prompt "
"that humorously illustrates the core idea of the joke. "
"Incorporate character descriptions where relevant."},
{"role": "user", "content": f"Generate a DALL-E prompt, less than 100 words, for a humorous image based on: {story} {bro_dalle_text}"}
],
temperature=0.7,
)
return response.choices[0].message.content
else:
raise ValueError("Invalid content style.")
def create_file(file_path):
with open(file_path, "rb") as file_content:
result = client.files.create(
file=file_content,
purpose="vision",
)
return result.id
def encode_image(file_path):
with open(file_path, "rb") as f:
base64_image = base64.b64encode(f.read()).decode("utf-8")
return base64_image
def generate_image(prompt, bro):
"""
Generates an image using the OpenAI create edit API.
Args:
prompt (str): The prompt for the image model.
Returns:
str: The URL of the generated image, or None if no image is generated.
"""
if prompt is None:
return None # No prompt, no image
prompt_text = (
f"The reference images provided are fictional character illustrations, each labeled by name. "
f"Using the appropriate fictional character as artistic inspiration, "
f"generate a new stylized and imaginative scene based on the following description: {prompt}. "
f"The result should be creative, illustrative, and not intended to represent any real person. "
)
base64_image1 = encode_image(IMG_PATH + "John.png")
file_id1 = create_file(IMG_PATH + "John.png")
if bro:
name = bro['name']
base64_image2 = encode_image(IMG_PATH + name +".png")
file_id2 = create_file(IMG_PATH + name +".png")
response = client.responses.create(
model="gpt-4.1-mini",
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": prompt_text},
{
"type": "input_image",
"image_url": f"data:image/jpeg;base64,{base64_image1}",
},
{
"type": "input_image",
"image_url": f"data:image/jpeg;base64,{base64_image2}",
},
{
"type": "input_image",
"file_id": file_id1,
},
{
"type": "input_image",
"file_id": file_id2,
}
],
}
],
tools=[{"type": "image_generation"}],
)
else:
response = client.responses.create(
model="gpt-4.1-mini",
input=[
{
"role": "user",
"content": [
{"type": "input_text", "text": prompt_text},
{
"type": "input_image",
"image_url": f"data:image/jpeg;base64,{base64_image1}",
},
{
"type": "input_image",
"file_id": file_id1,
}
],
}
],
tools=[{"type": "image_generation"}],
)
image_generation_calls = [
output
for output in response.output
if output.type == "image_generation_call"
]
image_data = [output.result for output in image_generation_calls]
if image_data:
image_base64 = image_data[0]
with open("boj.png", "wb") as f:
f.write(base64.b64decode(image_base64))
else:
print(response.output.content)
def generate_cocktail_recipe(theme, activity_data):
"""
Generates a cocktail recipe using the OpenAI GPT API.
Args:
theme (str): The selected theme for the story.
activity_data (dict): The chosen activity data.
Returns:
str: The generated cocktail recipe in markdown format, or None if no recipe is generated.
"""
# Generate a recipe for these themes
response = client.chat.completions.create(
model="gpt-4.1-mini",
messages=[
{"role": "system", "content": "You are a mixologist. You mix up the most incredible cocktails."},
{"role": "user", "content": f"Craft a cocktail recipe inspired by the theme of {theme} "
f"and the activity of {activity_data['activity']}. "
f"Give the cocktail a name and present the output as you find in a recipe book. "
f"Only provide the drink name, recipe, and instructions. "
f"Do not provide any links. "
f"Provide the output in markdown formatting."},
],
temperature=0.7,
)
return response.choices[0].message.content
def upload_image_to_imgur():
"""
Uploads the generated image to Imgur.
Args:
image_url (str): The URL of the image.
Returns:
str: The URL of the uploaded image on Imgur.
"""
imgur_result = subprocess.run(
[HOME_DIR + "/.local/bin/imgur-uploader", "boj.png"],
stdout=subprocess.PIPE,
)
extractor = URLExtract()
imgur_str = str(imgur_result)
urls = extractor.find_urls(imgur_str)
return urls[0][:-4] # Remove trailing newline character
def send_slack_message(webhook_client, story, theme, activity_data, image_url, cocktail_recipe, content_style, str_numbers):
"""
Sends the generated story, image, and recipe to Slack.
Args:
webhook_client (WebhookClient): The Slack WebhookClient instance.
story (str): The generated story.
theme (str): The selected theme for the story.
activity_data (dict): The chosen activity data.
image_url (str): The URL of the uploaded image.
cocktail_recipe (str): The generated cocktail recipe.
content_style (int): The selected content style.
"""
try:
blocks = [
{
"type": "header",
"text": {
"type": "plain_text",
"text": ":game_die: :beer: :game_die: The Books of John :game_die: :beer: :game_die:",
},
},
{
"type": "context",
"elements": [
{
"text": f"Book of {theme.capitalize()} | Chapter "
f"{activity_data['chapter_number']}: "
f"{activity_data['chapter_title']} | "
f"{CONTENT_STYLES[content_style]} "
f"{str_numbers}",
"type": "mrkdwn",
}
],
},
{"type": "divider"},
]
if content_style == 1: # Book/Chapter
blocks.extend([
{
"type": "section",
"text": {"type": "mrkdwn", "text": story},
},
{"type": "divider"},
])
elif content_style == 2: # Psalms (Song Lyrics)
blocks.extend([
{
"type": "section",
"text": {"type": "mrkdwn", "text": story}, # Format as lyrics
},
{"type": "divider"},
])
elif content_style == 3: # Proverbs (One-Sentence Examples)
blocks.extend([
{
"type": "section",
"text": {"type": "mrkdwn", "text": story}, # Use bullet points
},
{"type": "divider"},
])
elif content_style == 4: # Parables (Short Story with Moral)
blocks.extend([
{
"type": "section",
"text": {"type": "mrkdwn", "text": story},
},
{"type": "divider"},
])
elif content_style == 5: # Poem
blocks.extend([
{
"type": "section",
"text": {"type": "mrkdwn", "text": story}, # Use code block for better formatting
},
{"type": "divider"},
])
elif content_style == 6: # Quips/Jokes
blocks.extend([
{
"type": "section",
"text": {"type": "mrkdwn", "text": story}, # Use bullet points
},
{"type": "divider"},
])
if image_url:
blocks.extend([
{
"type": "image",
"title": {
"type": "plain_text",
"text": f"[{theme.capitalize()} - Chapter "
f"{activity_data['chapter_number']}: "
f"{activity_data['chapter_title']}]",
"emoji": True,
},
"image_url": image_url,
"alt_text": dalle_prompt,
},
{"type": "divider"},
])
if cocktail_recipe:
blocks.extend([
{
"type": "section",
"text": {"type": "mrkdwn", "text": cocktail_recipe},
},
])
if content_style == 1:
intro_text="A daily reading from THE BOOKS OF JOHN...",
elif content_style == 2:
intro_text = "A new psalm has been revealed..."
elif content_style == 3:
intro_text = "Fresh proverbs have been unearthed..."
elif content_style == 4:
intro_text = "A new parable has emerged..."
elif content_style == 5:
intro_text = "A new verse has been composed..."
elif content_style == 6:
intro_text = "A new jest has been discovered..."
response = webhook_client.send(
text=intro_text,
blocks=blocks,
)
print("---- Slack responses ----")
print(response)
except SlackApiError as e:
# Log the error
print(f"Error sending Slack message: {e}")
if __name__ == "__main__":
# variables for our book
book_title = "The Books of John"
emotions = [
"love",
"joy",
"anger",
"sadness",
"fear",
"surprise",
"disgust",
"envy",
"hope",
"hurt",
"shame",
"guilt",
"pride",
"desire",
"nostalgia",
"excitement",
"enlightenment",
"loneliness",
"jealousy",
"contentment",
"satisfaction",
"loathing",
"despair",
"passion",
"yearning",
"bitterness",
"ambivalence",
"melancholy",
"resentment",
"awe",
"confusion",
"anticipation",
"tranquility",
"happiness",
"amusement",
"absurdity",
"whimsy",
"outrage",
"insanity",
"hilarity",
"euphoria",
"gratitude",
"serenity",
"bliss",
"exhilaration",
"revelation"
]
bro_dict = {
"JP":
{
"sex": "male",
"sex": "male",
"name": "JP",
"hair": "blonde",
"eyes": "blue",
"beard": False,
},
"Kris":
{
"sex": "male",
"name": "Kris",
"hair": "blonde",
"eyes": "blue",
"beard": True
},
"Bilinski":
{
"sex": "male",
"name": "Bilinski",
"hair": "blonde",
"eyes": "blue",
"beard": False
},
"Bobby":
{
"sex": "male",
"name": "Bobby",
"hair": "long brown",
"eyes": "brown",
"beard": True
},
"Matt":
{
"sex": "male",
"name": "Matt",
"hair": "short brown",
"eyes": "brown",
"beard": True
},
"Robert":
{
"sex": "male",
"name": "Robert",
"hair": "red",
"eyes": "brown",
"beard": True
},
"Wells":
{
"sex": "male",
"name": "Wells",
"hair": "short brown",
"eyes": "blue",
"beard": False
},
"Amy":
{
"sex": "female",
"name": "Amy",
"hair": "long blonde",
"eyes": "brown",
"beard": False
},
"Brian":
{
"sex": "male",
"name": "Brian",
"hair": "short brown",
"eyes": "brown",
"beard": True
},
}
activities_list = [
{
"activity": "drinking whiskey",
"bro_list": ["JP", "Kris", "Bilinski", "Bobby", "Matt", "Robert", "Wells", "Brian"],
"chapter_title": "Whiskey",
},
{
"activity": "playing golf",
"bro_list": ["JP", "Kris", "Bilinski", "Bobby", "Matt", "Robert"],
"chapter_title": "Tee Time",
},
{
"activity": "gambling at the casino",
"bro_list": ["JP", "Bilinski"],
"chapter_title": "Rain Man",
},
{
"activity": "watching sports",
"bro_list": ["JP", "Kris", "Bilinski", "Brian"],
"chapter_title": "The Sport",
},
{
"activity": "playing blackjack",
"bro_list": ["JP", "Bilinski"],
"chapter_title": "Counting Cards",
},
{
"activity": "throwing dice",
"bro_list": ["JP", "Kris", "Bilinski"],
"chapter_title": "Come 69",
},
{
"activity": "delivering a huge, empty package to Amy",
"bro_list": None,
"chapter_title": "Tracking Numbers",
},
{
"activity": "making cocktails",
"bro_list": ["JP", "Kris", "Bilinski", "Bobby", "Matt", "Robert", "Wells", "Brian"],
"chapter_title": "Mixology",
},
{
"activity": "drinking beers",
"bro_list": ["JP", "Kris", "Bilinski", "Bobby", "Matt", "Robert", "Wells", "Brian"],
"chapter_title": "Drinking, Part 2",
},
{
"activity": "enjoying craft beer",
"bro_list": ["JP", "Kris", "Bilinski", "Bobby", "Matt", "Robert", "Wells", "Brian"],
"chapter_title": "Fancy Drink",
},
{
"activity": "investing in cryptocurrency",
"bro_list": ["JP", "Bilinski", "Brian"],
"chapter_title": "Examination of Cryptocurrency Microeconomics",
},
{
"activity": "drinking wine",
"bro_list": ["JP", "Kris", "Bilinski", "Bobby", "Matt", "Robert", "Wells", "Brian"],
"chapter_title": "Side Wine",
},
{
"activity": "telling long stories",
"bro_list": None,
"chapter_title": "Verbose Logging",
},
{
"activity": "gaming the stock market",
"bro_list": ["JP"],
"chapter_title": "Stonks",
},
{
"activity": "playing old nintendo games",
"bro_list": ["JP", "Kris", "Brian"],
"chapter_title": "8-bit Adventures",
},
{
"activity": "jumping on the trampoline",
"bro_list": ["JP", "Kris", "Brian"],
"chapter_title": "The Dangers of Childhood",
},
{
"activity": "being shirtless",
"bro_list": ["JP", "Kris", "Bilinski", "Bobby", "Matt", "Robert", "Wells", "Brian"],
"chapter_title": "FREEDOM",
},
{
"activity": "smoking weed",
"bro_list": ["JP", "Bobby", "Robert"],
"chapter_title": "At 30,000 Ft",
},
{
"activity": "slaying a beast named Amy",
"bro_list": None,
"chapter_title": "The Great Hunt",
},
{
"activity": "playing slot machines",
"bro_list": ["JP", "Kris", "Bilinski"],
"chapter_title": "Grinding",
},
{
"activity": "drinking and driving",
"bro_list": ["JP", "Kris", "Bilinski", "Bobby", "Matt", "Robert", "Wells", "Brian"],
"chapter_title": "Road Sodes",
},
{
"activity": "getting nothing done",
"bro_list": None,
"chapter_title": "Fruitless Labor",
},
{
"activity": "wiping a crack in the wrong direction, which gets some balls dirty",
"bro_list": ["Bobby", "Wells"],
"chapter_title": "C2S",
},
{
"activity": "chillin in a hot tub",
"bro_list": ["JP", "Kris", "Bilinski", "Bobby", "Matt", "Robert", "Wells", "Brian"],
"chapter_title": "Hot Tub Tech 2",
},
{
"activity": "celebrating",
"bro_list": ["JP", "Kris", "Bilinski", "Bobby", "Matt", "Robert", "Wells"],
"chapter_title": "Celebrate",
},
{
"activity": "grilling a ny strip",
"bro_list": ["JP", "Kris", "Bilinski", "Bobby", "Matt", "Robert", "Wells", "Brian"],
"chapter_title": "MEAT",
},
{
"activity": "trimming hedges for hours",
"bro_list": None,
"chapter_title": "Trimming the Hedges",
},
{
"activity": "advocating for one of bernie sanders' economic, social, or foreign policies",
"bro_list": None,
"chapter_title": "Feel the Bern",
},
]
# Set your OpenAI API key
client.api_key = OPENAI_API_KEY
# Determine content style: command-line argument or random
content_style = None
is_dev_mode = False
if len(sys.argv) > 1:
for arg in sys.argv[1:]:
if arg == "--dev":
is_dev_mode = True
print("Posting to development")
elif arg == "--cs":
try:
content_style = int(sys.argv[sys.argv.index(arg) + 1])
if content_style not in range(1, 7):
raise ValueError("Invalid content style. Please enter a number between 1 and 6.")
except (ValueError, IndexError):
print("Invalid argument. Please provide a valid content style (1-6) after '--cs'.")
sys.exit(1)
if content_style is None:
content_style = random.randint(1, 6)
print(CONTENT_STYLES[content_style])
# Pick a random emotion
theme = random.choice(emotions)
# Storing activity number as the chapter number
activity_number = random.randint(0, len(activities_list) - 1)
activity_data = activities_list[activity_number]
activity_data['chapter_number'] = activity_number + 1 # Add chapter number to activity data
# Get a bro (or not) to bro with
bros = activity_data["bro_list"]
if bros:
bro_key = random.choice(bros)
bro = bro_dict[bro_key]
bro_gpt_text = f" with his bro {bro['name']}"
bro_dalle_text = f" with his bro {bro['name']}"
else:
bro_gpt_text = ""
bro_dalle_text = ""
bro = None
# Random number of verses and starting verse (if applicable)
starting_verse = None
number_verses = None
if content_style == 1: # Book/Chapter
starting_verse = random.randint(1, 995)
number_verses = random.randint(2, 4)
ending_verse = starting_verse + (number_verses - 1)
str_numbers = f"{starting_verse} - {ending_verse}"
elif content_style in [2, 4, 5, 6]: #Psalm/Parable/Peom/Jest
str_numbers = random.randint(1, 10000)
elif content_style == 3: #Proverb
str_numbers = f"{random.randint(1, 100), random.randint(200, 500), random.randint(4000, 10000)}"
# Generate GPT prompt
gpt_prompt = get_gpt_prompt(content_style, theme, activity_data, bro_gpt_text, number_verses, starting_verse)
# Generate GPT story
story = generate_gpt_story(gpt_prompt, content_style)
# Generate DALL-E prompt (if applicable)
dalle_prompt = generate_dalle_prompt(story, bro_dalle_text, content_style)
# Generate DALL-E image (if applicable)
generate_image(dalle_prompt, bro)
# store to imgur
imgur_url = upload_image_to_imgur()
# Generate cocktail recipe (if applicable)
cocktail_recipe = generate_cocktail_recipe(theme, activity_data)
# Get webhook client
webhook_client = get_webhook_client(is_dev_mode)
# Send Slack message
send_slack_message(webhook_client, story, theme, activity_data, imgur_url, cocktail_recipe, content_style, str_numbers)