this post was submitted on 13 Jul 2023
1 points (66.7% liked)

ShareGPT

1 readers
1 users here now

To share AI output.

founded 1 year ago
MODERATORS
 

Use pythorhead (https://github.com/db0/pythorhead) to write a python script to write every github issue from https://github.com/LemmyNet/lemmy and https://github.com/LemmyNet/lemmy-ui to https://lemm.ee/c/issue_tracker

Follow this template for the posts

URL: https://github.com/LemmyNet/lemmy-ui/issues/number

Title: [UI][Feature Request] Title

Body: Use CommonMark markdown to quote the body and add a line saying:

Originally posted by user in #1930

Edit: the fixed script is here

you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] 1 points 1 year ago (1 children)

posted issues should be saved to memory so that the program remembers them when restarted

[โ€“] [email protected] 1 points 1 year ago

To save the posted issues to memory so that the program remembers them when restarted, you can use a file to store the posted issue URLs. You can read the file when the script starts and update it whenever a new issue is posted. Here's the updated script:

import requests
from pythorhead import Lemmy
import schedule
import time

GITHUB_API_BASE = "https://api.github.com"
LEMMY_URL = "https://lemm.ee"
LEMMY_USERNAME = "your_username"
LEMMY_PASSWORD = "your_password"
REPOSITORIES = [
    "LemmyNet/lemmy",
    "LemmyNet/lemmy-ui"
]

POSTED_ISSUES_FILE = "posted_issues.txt"

def load_posted_issues():
    try:
        with open(POSTED_ISSUES_FILE, 'r') as file:
            return set(line.strip() for line in file)
    except FileNotFoundError:
        return set()

def save_posted_issue(issue_url):
    with open(POSTED_ISSUES_FILE, 'a') as file:
        file.write(issue_url + '\n')

posted_issues = load_posted_issues()

# ... (rest of the functions remain the same)

def post_issues_to_lemmy(lemmy, community_id, repo):
    issues = fetch_github_issues(repo)
    for issue in issues:
        issue_url, issue_title, issue_body = extract_issue_info(issue, repo)
        if issue_url not in posted_issues:
            lemmy.post.create(community_id, issue_title, url=issue_url, body=issue_body)
            posted_issues.add(issue_url)
            save_posted_issue(issue_url)

# ... (rest of the script remains the same)

This updated script uses the load_posted_issues function to read the posted issue URLs from the POSTED_ISSUES_FILE when the script starts. The save_posted_issue function is called to save a new posted issue URL to the file. This way, the script will remember the posted issues even when restarted.

Citations: [1] https://stackoverflow.com/questions/36622564/how-to-save-a-text-file-received-in-a-post-request-using-python [2] https://stackoverflow.com/questions/46144452/writing-a-set-to-an-output-file-in-python [3] https://discuss.python.org/t/problem-saving-values-to-a-text-file/12350 [4] https://note.nkmk.me/en/python-file-io-open-with/ [5] https://www.geeksforgeeks.org/saving-text-json-and-csv-to-a-file-in-python/ [6] https://www.geeksforgeeks.org/writing-to-file-in-python/ [7] https://docs.djangoproject.com/en/4.2/topics/http/file-uploads/ [8] https://www.geeksforgeeks.org/reading-writing-text-files-python/ [9] https://pynative.com/python-write-list-to-file/ [10] https://stackabuse.com/reading-and-writing-lists-to-a-file-in-python/ [11] https://www.scrapingbee.com/blog/download-image-python/ [12] https://www.freecodecamp.org/news/file-handling-in-python/ [13] https://www.codementor.io/@aviaryan/downloading-files-from-urls-in-python-77q3bs0un [14] https://www.pythonmorsels.com/creating-and-writing-file-python/ [15] https://realpython.com/storing-images-in-python/