-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from usegalaxy-eu/Initial-commit
Add Galaxy Social Assistent bot
- Loading branch information
Showing
10 changed files
with
607 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Create PR for new citations | ||
|
||
on: | ||
schedule: | ||
- cron: "00 00 * * *" | ||
|
||
workflow_dispatch: | ||
inputs: | ||
days: | ||
description: "Number of days before today to check for new citations" | ||
required: false | ||
default: "5" | ||
|
||
jobs: | ||
citation-bot: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install -r requirements.txt | ||
- name: Generate a token | ||
id: generate-token | ||
uses: actions/create-github-app-token@v1 | ||
with: | ||
app-id: ${{ vars.APP_ID }} | ||
private-key: ${{ secrets.APP_PRIVATE_KEY }} | ||
owner: "arash77" | ||
repositories: "galaxy-social-main" | ||
|
||
- name: Run python script | ||
env: | ||
GALAXY_SOCIAL_BOT_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
REPO: "arash77/galaxy-social-main" | ||
DAYS: ${{ github.event.inputs.days || '5' }} | ||
run: python -u app/citation_bot.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Create PR for RSS/Atom feeds | ||
|
||
on: | ||
schedule: | ||
- cron: "00 00 * * *" | ||
|
||
workflow_dispatch: | ||
inputs: | ||
days: | ||
description: "Number of days before today to check for new feeds" | ||
required: false | ||
default: "5" | ||
|
||
jobs: | ||
feed-bot: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install -r requirements.txt | ||
- name: Generate a token | ||
id: generate-token | ||
uses: actions/create-github-app-token@v1 | ||
with: | ||
app-id: ${{ vars.APP_ID }} | ||
private-key: ${{ secrets.APP_PRIVATE_KEY }} | ||
owner: "arash77" | ||
repositories: "galaxy-social-main" | ||
|
||
- name: Run python script | ||
env: | ||
GALAXY_SOCIAL_BOT_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
REPO: "arash77/galaxy-social-main" | ||
DAYS: ${{ github.event.inputs.days || '5' }} | ||
run: python -u app/feed_bot.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
name: Create PR for youtube videos | ||
|
||
on: | ||
schedule: | ||
- cron: "00 00 * * *" | ||
|
||
workflow_dispatch: | ||
inputs: | ||
days: | ||
description: "Number of days before today to check for new videos" | ||
required: false | ||
default: "5" | ||
|
||
jobs: | ||
youtube-bot: | ||
runs-on: ubuntu-latest | ||
permissions: | ||
contents: write | ||
pull-requests: write | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v5 | ||
with: | ||
python-version: "3.10" | ||
|
||
- name: Install dependencies | ||
run: | | ||
python -m pip install --upgrade pip | ||
python -m pip install -r requirements.txt | ||
- name: Generate a token | ||
id: generate-token | ||
uses: actions/create-github-app-token@v1 | ||
with: | ||
app-id: ${{ vars.APP_ID }} | ||
private-key: ${{ secrets.APP_PRIVATE_KEY }} | ||
owner: "arash77" | ||
repositories: "galaxy-social-main" | ||
|
||
- name: Run python script | ||
env: | ||
GALAXY_SOCIAL_BOT_TOKEN: ${{ steps.generate-token.outputs.token }} | ||
REPO: "arash77/galaxy-social-main" | ||
DAYS: ${{ github.event.inputs.days || '5' }} | ||
run: python -u app/youtube_bot.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,25 @@ | ||
# galaxy-social-assistent | ||
# Galaxy Social Assistent | ||
|
||
## About | ||
|
||
This bot automatically creates posts on Galaxy Social by adding pull requests to the [Galaxy Social repository](https://github.com/usegalaxy-eu/galaxy-social/). | ||
|
||
## Currently Supported Inputs | ||
|
||
* RSS and Atom feeds | ||
* YouTube | ||
* Citations from Zotero | ||
|
||
## In Development | ||
|
||
The bot is being extended to support input from: | ||
|
||
* GitHub issues and PRs | ||
* Galaxy User Statistics | ||
* Galaxy citations | ||
* Galaxy tools | ||
|
||
## Usage | ||
|
||
This bot will work automatically and you just need to change the `config.yml` file to config what to be posted and what to include when the PR has been created. | ||
Also the [Galaxy Social bot app](https://github.com/apps/galaxy-social-bot) should be installed on the Galaxy Social repository and the app id and the private key should be given to this repo as variable (vars.APP_ID) and secret (secrets.APP_PRIVATE_KEY). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import os | ||
|
||
from dateutil import parser | ||
from pyzotero import zotero, zotero_errors | ||
from utils import utils | ||
|
||
|
||
def main(): | ||
citation_bot_path = os.environ.get("CITATION_BOT_PATH", "posts/citation_bot") | ||
config_name = "citations" | ||
utils_obj = utils(citation_bot_path, config_name) | ||
|
||
for citation in utils_obj.list: | ||
if citation.get("zotero_group_id") is None: | ||
raise ValueError( | ||
f"No zotero group id found in the file for citation {citation}" | ||
) | ||
try: | ||
zot = zotero.Zotero(citation.get("zotero_group_id"), "group") | ||
if citation.get("tag"): | ||
zot.add_parameters(tag=citation.get("tag")) | ||
try: | ||
items = zot.everything(zot.top()) | ||
except zotero_errors.HTTPError: | ||
# try again | ||
items = zot.everything(zot.top()) | ||
except Exception as e: | ||
print( | ||
f"Error in connecting to zotero group {citation.get('zotero_group_id')}: {e}" | ||
) | ||
continue | ||
|
||
folder = citation.get("zotero_group_id") | ||
format_string = citation.get("format") | ||
entry_processed = [] | ||
|
||
for item in items: | ||
data = item["data"] | ||
|
||
data["title"] = ( | ||
data.get("title", "").encode("ASCII", "ignore").decode("ASCII") | ||
) | ||
data["creators"] = ", ".join( | ||
( | ||
f"{creator.get('lastName', '')}, {creator.get('firstName', '')[0]}." | ||
if creator.get("firstName") is not None | ||
else f"{creator.get('lastName', '')}" | ||
) | ||
for creator in data.get("creators", [])[:3] | ||
) + (", et. al." if len(data.get("creators", [])) > 3 else "") | ||
|
||
data["dateAdded"] = ( | ||
parser.isoparse(data["dateAdded"]).date() if "dateAdded" in data else "" | ||
) | ||
formatted_text = format_string.format(**data) | ||
|
||
entry_data = { | ||
"title": data["title"], | ||
"config": citation, | ||
"date": data["dateAdded"], | ||
"rel_file_path": f"{folder}/{item['key']}.md", | ||
"formatted_text": formatted_text, | ||
} | ||
if utils_obj.process_entry(entry_data): | ||
entry_processed.append(f"[{data['title']}]({data['url']})") | ||
|
||
title = f"Update from citation input bot since {utils_obj.start_date.strftime('%Y-%m-%d')}" | ||
entry_processed_str = "- " + "\n- ".join(entry_processed) | ||
body = f"This PR created automatically by citation bot.\n\nCitations processed:\n{entry_processed_str}" | ||
utils_obj.create_pull_request(title, body) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
import os | ||
|
||
import feedparser | ||
from dateutil import parser | ||
from markdownify import markdownify | ||
from utils import utils | ||
|
||
|
||
def main(): | ||
feed_bot_path = os.environ.get("FEED_BOT_PATH", "posts/feed_bot") | ||
config_name = "feeds" | ||
utils_obj = utils(feed_bot_path, config_name) | ||
|
||
for feed in utils_obj.list: | ||
if feed.get("url") is None: | ||
raise ValueError(f"No url found in the file for feed {feed}") | ||
try: | ||
feed_data = feedparser.parse(feed.get("url")) | ||
except Exception as e: | ||
print(f"Error in parsing feed {feed.get('url')}: {e}") | ||
continue | ||
|
||
folder = feed_data.feed.title.replace(" ", "_").lower() | ||
format_string = feed.get("format") | ||
feeds_processed = [] | ||
for entry in feed_data.entries: | ||
date_entry = ( | ||
entry.get("published") or entry.get("pubDate") or entry.get("updated") | ||
) | ||
published_date = parser.isoparse(date_entry).date() | ||
|
||
if entry.link is None: | ||
print(f"No link found: {entry.title}") | ||
continue | ||
|
||
file_name = entry.link.split("/")[-1] or entry.link.split("/")[-2] | ||
|
||
entry["content"] = ( | ||
markdownify(entry.content[0].value).strip() | ||
if "content" in entry | ||
else "" | ||
) | ||
|
||
formatted_text = format_string.format(**entry) | ||
|
||
entry_data = { | ||
"title": entry.title, | ||
"config": feed, | ||
"date": published_date, | ||
"rel_file_path": f"{folder}/{file_name}.md", | ||
"formatted_text": formatted_text, | ||
} | ||
if utils_obj.process_entry(entry_data): | ||
feeds_processed.append(f"[{entry.title}]({entry.link})") | ||
|
||
title = ( | ||
f"Update from feeds input bot since {utils_obj.start_date.strftime('%Y-%m-%d')}" | ||
) | ||
feeds_processed_str = "- " + "\n- ".join(feeds_processed) | ||
body = f"This PR created automatically by feed bot.\n\nFeeds processed:\n{feeds_processed_str}" | ||
utils_obj.create_pull_request(title, body) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
Oops, something went wrong.