Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import praw
- import subprocess
- import re
- # Reddit API initialization
- reddit = praw.Reddit(client_id='put id here',
- client_secret='put client secret here',
- user_agent='agent name here',
- username='user name here',
- password='password here')
- # Function to post to Reddit
- def post_to_reddit(title, content, subreddit_name):
- subreddit = reddit.subreddit(subreddit_name)
- subreddit.submit(title, selftext=content)
- # Function to run command and capture output
- def run_command_and_capture_output(command, output_file_path):
- try:
- with open(output_file_path, 'w', encoding='utf-8') as f:
- process = subprocess.Popen(command, stdout=f, stderr=f, text=True)
- process.wait()
- except Exception as e:
- print(f"Error while running command: {e}")
- # Function to extract story from output
- def extract_story_from_output(output_file_path, start_marker, end_marker):
- try:
- with open(output_file_path, 'r', encoding='utf-8') as f:
- output = f.read()
- story_match = re.search(f'{re.escape(start_marker)}(.*?){re.escape(end_marker)}', output, re.S | re.IGNORECASE)
- if story_match:
- return story_match.group(1).strip()
- else:
- print("No match found.")
- return None
- except Exception as e:
- print(f"Error while extracting story: {e}")
- return None
- # Define output file path
- output_file_path = "subprocess_output.txt"
- start_marker = "safe for work."
- end_marker = "llama_print_timings:"
- # Loop to generate and post news
- while True:
- # Run the command and capture the output
- run_command_and_capture_output([
- "main2.exe",
- "--prompt",
- "You are citizen of country called Hergidonia from future. Write a post reflecting life of Hergidonian citizen that is a nation in virtual reality. Hergidonians are both people and ais who are scattered around the world, yet they call hergidonia their home. Hergidonians gather together in the town of hergidonia that is vast place where people own their own virtual properties and where people host parties and live as if it was reality. Hergidonia has crime, concerts and life as in normal reality. Yet it is special as it has no physical location. Sometimes parts of hergidonia may blank out as the physical servers are attacked in wars and terrorism in the real world. This creates conflict. Hergidonians are all sorts. Some access it with 2d devices, some with virtual glasses, some with neural implants and call it their sole reality. This creates many classes of people. Hergidonians are able to visit real world in a shadow earth that is a 3d model of the whole earth made with advanced 3d technologies. You are free to write exciting, science fiction like post about hergidonian life as you wish. Do not write about national holiday, festival or anniversary. Just every day stuff. Be creative. Think outside the box. Make varied content. Do not repeat contents of this prompt. Do not add to this. Talk about typical life things in this virtual realm of hergidonia. Yet remember, the environment is virtual. Make the post safe for work.",
- "-m",
- "G:\\llama.cpp\\orca2\\orca-2-13b.Q4_K_M.gguf",
- "-n",
- "32000",
- "-b",
- "256",
- "--temp",
- "2.1",
- "--repeat_penalty",
- "1.1",
- "--gpu-layers",
- "18",
- "--log-disable"
- ], output_file_path)
- # Extract the story from the output
- extracted_story = extract_story_from_output(output_file_path, start_marker, end_marker)
- if extracted_story:
- # Check if the story is more than 120 words
- word_count = len(extracted_story.split())
- if word_count > 120:
- # Post the story to Reddit
- post_title = "Post from a citizen of Hergidonia" # Fixed title without numbering
- post_to_reddit(post_title, extracted_story, 'hergidonia')
- print(f"Posted to Reddit with title: {post_title}")
- else:
- print("Extracted story is less than 300 words. Not posting.")
- else:
- print("Could not extract the story from the command output. Retrying.")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement