Compare commits
16 Commits
Author | SHA1 | Date | |
---|---|---|---|
2eeaa34401
|
|||
9bd34aeb2a
|
|||
99d307a2a7
|
|||
b412eafc97
|
|||
2e3c034eed
|
|||
e593c71fc1
|
|||
a159c7ff8e
|
|||
e10082d96c
|
|||
f48dd5dcf5
|
|||
9b00d5d6ee
|
|||
467defdffe
|
|||
3ed5ef7079 | |||
05218ad6b2
|
|||
83662cd415
|
|||
1213e08c7b
|
|||
8605f7f732
|
@ -1,14 +1,12 @@
|
|||||||
name: QuotesBot
|
name: QuotesBot
|
||||||
on:
|
on:
|
||||||
schedule:
|
schedule:
|
||||||
- cron '36 */4 * * *'
|
- cron: '35 */4 * * *'
|
||||||
permissions:
|
|
||||||
contents: read
|
|
||||||
jobs:
|
jobs:
|
||||||
deploy:
|
deploy:
|
||||||
runs: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v4
|
||||||
- name: Setup Python
|
- name: Setup Python
|
||||||
uses: actions/setup-python@v3
|
uses: actions/setup-python@v3
|
||||||
with:
|
with:
|
||||||
@ -17,7 +15,7 @@ jobs:
|
|||||||
run: |
|
run: |
|
||||||
python -m pip install --upgrade pip
|
python -m pip install --upgrade pip
|
||||||
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
|
||||||
- name: Run Script
|
- name: Run app.py
|
||||||
run:
|
run:
|
||||||
python app.py
|
python app.py
|
||||||
env:
|
env:
|
||||||
|
17
README.md
17
README.md
@ -1,6 +1,6 @@
|
|||||||
# The new [QuotesBot](https://bots.fyrfli.social/@quotesbot) code
|
# The new [QuotesBot](https://bots.fyrfli.social/@quotesbot) code 
|
||||||
|
|
||||||
In the neverending quest to improve my coding skills, I often check out the code that other bots employ Last night, I decided to check out the code for the [ThursdayBot](https://github.com/devashishp/thursday) and realised something really neat:
|
In the neverending quest to improve my coding skills, I often check out the code that other bots employ. Last night, I decided to check out the code for the [ThursdayBot](https://github.com/devashishp/thursday) and realised something really neat:
|
||||||
|
|
||||||
>[!IMPORTANT]
|
>[!IMPORTANT]
|
||||||
>***there is a way to make the bot completely foolproof!!!***
|
>***there is a way to make the bot completely foolproof!!!***
|
||||||
@ -25,15 +25,10 @@ Posts a quote every 4 hours from a file that you specify.
|
|||||||
- the CSV-Formatted file should include two (2) columns: "quote" and "author" (in that order) like:
|
- the CSV-Formatted file should include two (2) columns: "quote" and "author" (in that order) like:
|
||||||
|
|
||||||
```
|
```
|
||||||
[
|
quote,author
|
||||||
{
|
"Amet lorem voluptatem tempore sint quod? Nam porro aliquid aspernatur assumenda fugiat A odit excepturi facere vero nihil Nulla voluptate accusantium vero recusandae nulla Obcaecati nemo dolor non reprehenderit excepturi23", "Example Author"
|
||||||
"quote": "Amet lorem voluptatem tempore sint quod? Nam porro aliquid aspernatur assumenda fugiat A odit excepturi facere vero nihil Nulla voluptate accusantium vero recusandae nulla Obcaecati nemo dolor non reprehenderit excepturi23",
|
"Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla","Author Exemplaris",
|
||||||
"author": "Example Author",
|
...
|
||||||
"quote": "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Donec quam felis, ultricies nec, pellentesque eu, pretium quis, sem. Nulla",
|
|
||||||
"author": "Author Exemplaris",
|
|
||||||
...
|
|
||||||
}
|
|
||||||
]
|
|
||||||
```
|
```
|
||||||
|
|
||||||
### Steps
|
### Steps
|
||||||
|
5
app.py
5
app.py
@ -14,8 +14,9 @@ if source_object.reason == "OK":
|
|||||||
reader = csv.DictReader(io.StringIO(source_object.text))
|
reader = csv.DictReader(io.StringIO(source_object.text))
|
||||||
source_data = dumps(list(reader))
|
source_data = dumps(list(reader))
|
||||||
choices = loads(source_data)
|
choices = loads(source_data)
|
||||||
print(choices[0])
|
|
||||||
choice = choices[randint(0, len(choices) - 1)]
|
choice = choices[randint(0, len(choices) - 1)]
|
||||||
headers = {'Authorization': 'Bearer ' + post_token}
|
headers = {'Authorization': 'Bearer ' + post_token}
|
||||||
payload = {'status': f"{choice['quote']}\n\n - {choice['author']}", 'privacy': 'public'}
|
payload = {'status': f"{choice['quote']}\n\n - {choice['author']}\n\n#RandomQuote #quotes #quote #bot", 'visibility': 'public'}
|
||||||
response = post(post_endpoint, headers=headers, data=payload)
|
response = post(post_endpoint, headers=headers, data=payload)
|
||||||
|
print(response.reason)
|
||||||
|
print(loads(response.text)['url'])
|
||||||
|
Reference in New Issue
Block a user