This repository has been archived by the owner on Sep 10, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 162
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 #43 from andrlik/master
- Loading branch information
Showing
4 changed files
with
142 additions
and
63 deletions.
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 |
---|---|---|
|
@@ -7,20 +7,22 @@ This project should work in the latest releases of Python 2.7 and Python 3. By d | |
## Setup | ||
|
||
1. Clone this repo | ||
2. Create a Twitter account that you will post to. | ||
3. Sign into https://dev.twitter.com/apps with the same login and create an application. Make sure that your application has read and write permissions to make POST requests. | ||
4. Make a copy of the `local_settings_example.py` file and name it `local_settings.py` | ||
5. Take the consumer key (and secret) and access token (and secret) from your Twiter application and paste them into the appropriate spots in `local_settings.py`. | ||
2. Make a copy of the `local_settings_example.py` file and name it `local_settings.py` | ||
3. If posting to Twitter, create a Twitter account that you will post to. | ||
4. Sign into https://dev.twitter.com/apps with the same login and create an application. Make sure that your application has read and write permissions to make POST requests. | ||
5. Set `ENABLE_TWITTER` to `True`. Take the consumer key (and secret) and access token (and secret) from your Twiter application and paste them into the appropriate spots in `local_settings.py`. | ||
6. In `local_settings.py`, be sure to add the handle of the Twitter user you want your _ebooks account to be based on. To make your tweets go live, change the `DEBUG` variable to `False`. | ||
7. Create an account at Heroku, if you don't already have one. [Install the Heroku toolbelt](https://devcenter.heroku.com/articles/quickstart#step-2-install-the-heroku-toolbelt) and set your Heroku login on the command line. | ||
8. Type the command `heroku create` to generate the _ebooks Python app on the platform that you can schedule. | ||
9. The only Python requirement for this script is [python-twitter](https://github.com/bear/python-twitter), the `pip install` of which is handled by Heroku automatically. | ||
9. `git commit -am 'updated the local_settings.py'` | ||
10. `git push heroku master` | ||
11. Test your upload by typing `heroku run worker`. You should either get a response that says "3, no, sorry, not this time" or a message with the body of your post. If you get the latter, check your _ebooks Twitter account to see if it worked. | ||
12. Now it's time to configure the scheduler. `heroku addons:create scheduler:standard` | ||
13. Once that runs, type `heroku addons:open scheduler`. This will open up a browser window where you can adjust the time interval for the script to run. The scheduled command should be `python ebooks.py`. I recommend setting it at one hour. | ||
14. Sit back and enjoy the fruits of your labor. | ||
7. If you also want to include Mastodon as a source set `ENABLE_MASTODON` to `True` and you'll need to create a Mastodon account to send to on an instance like [botsin.space](https://botsin.space). | ||
8. After creating the Mastodon account, open a python prompt in your project directory and follow the [directions below](#mastodon-setup). Update your `local_settings.py` file with the filenames of the generated client secret and user credential secret files. | ||
9. Create an account at Heroku, if you don't already have one. [Install the Heroku toolbelt](https://devcenter.heroku.com/articles/quickstart#step-2-install-the-heroku-toolbelt) and set your Heroku login on the command line. | ||
10. Type the command `heroku create` to generate the _ebooks Python app on the platform that you can schedule. | ||
11. The only Python requirements for this script are [python-twitter](https://github.com/bear/python-twitter), Mastodon.py, and BeautfulSoup; the `pip install` of which is handled by Heroku automatically. | ||
12. `git commit -am 'updated the local_settings.py'` | ||
13. `git push heroku master` | ||
14. Test your upload by typing `heroku run worker`. You should either get a response that says "3, no, sorry, not this time" or a message with the body of your post. If you get the latter, check your _ebooks Twitter account to see if it worked. | ||
15. Now it's time to configure the scheduler. `heroku addons:create scheduler:standard` | ||
16. Once that runs, type `heroku addons:open scheduler`. This will open up a browser window where you can adjust the time interval for the script to run. The scheduled command should be `python ebooks.py`. I recommend setting it at one hour. | ||
17. Sit back and enjoy the fruits of your labor. | ||
|
||
|
||
## Configuring | ||
|
@@ -72,8 +74,25 @@ After that, commit the change and `git push heroku master`. Then run the command | |
|
||
If you want to avoid hitting the Twitter API and instead want to use a static text file, you can do that. First, create a text file containing a Python list of quote-wrapped tweets. Then set the `STATIC_TEST` variable to `True`. Finally, specify the name of text file using the `TEST_SOURCE` variable in `local_settings.py` | ||
|
||
## Mastodon Setup | ||
|
||
You only need to do this once! | ||
|
||
```python | ||
>>> from mastodon import Mastodon | ||
>>> Mastodon.create_app('pytooterapp', api_base_url='YOUR INSTANCE URL', to_file='YOUR_FILENAME_HERE') | ||
``` | ||
|
||
Then, create a user credential file. NOTE: Your bot has to follow your source account. | ||
|
||
```python | ||
>>> mastodon = Mastodon(client_id='YOUR_FILENAME_HERE', api_base_url='YOUR INSTANCE URL') | ||
>>> mastodon.log_in('[email protected]','incrediblygoodpassword',to_file='YOUR USER FILENAME HERE') | ||
``` | ||
|
||
Commit those two files to your repository and you can toot away. | ||
|
||
## Credit | ||
As I said, this is based almost entirely on [@harrisj's](https://twitter.com/harrisj) [iron_ebooks](https://github.com/harrisj/iron_ebooks/). He created it in Ruby, and I wanted to port it to Python. All the credit goes to him. As a result, all of the blame for clunky implementation in Python fall on me. | ||
|
||
Many thanks to the [many folks who have contributed](CONTRIBUTORS.md) to the development of this project since it was open sourced in 2013. If you see ways to improve the code, please fork it and send a [pull request](https://github.com/tommeagher/heroku_ebooks/pulls), or [file an issue](https://github.com/tommeagher/heroku_ebooks/issues) for me, and I'll address it. | ||
Many thanks to the [many folks who have contributed](CONTRIBUTORS.md) to the development of this project since it was open sourced in 2013. If you see ways to improve the code, please fork it and send a [pull request](https://github.com/tommeagher/heroku_ebooks/pulls), or [file an issue](https://github.com/tommeagher/heroku_ebooks/issues) for me, and I'll address it. |
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
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 |
---|---|---|
|
@@ -2,14 +2,25 @@ | |
Local Settings for a heroku_ebooks account. | ||
''' | ||
|
||
# Twitter API configuration | ||
# Configuration for Twitter API | ||
ENABLE_TWITTER_SOURCES = True # Fetch twitter statuses as source | ||
ENABLE_TWITTER_POSTING = True # Tweet resulting status? | ||
MY_CONSUMER_KEY = 'Your Twitter API Consumer Key' | ||
MY_CONSUMER_SECRET = 'Your Consumer Secret Key' | ||
MY_ACCESS_TOKEN_KEY = 'Your Twitter API Access Token Key' | ||
MY_ACCESS_TOKEN_SECRET = 'Your Access Token Secret' | ||
|
||
# Sources (Twitter, local text file or a web page) | ||
# Configuration for Mastodon API | ||
ENABLE_MASTODON_SOURCES = False # Fetch mastodon statuses as a source? | ||
ENABLE_MASTODON_POSTING = False # Toot resulting status? | ||
MASTODON_API_BASE_URL = "" # an instance url like https://botsin.space | ||
CLIENT_CRED_FILENAME = '' # the MASTODON client secret file you created for this project | ||
USER_ACCESS_FILENAME = '' # The MASTODON user credential file you created at installation. | ||
|
||
# Sources (Twitter, Mastodon, local text file or a web page) | ||
SOURCE_ACCOUNTS = [""] # A list of comma-separated, quote-enclosed Twitter handles of account that you'll generate tweets based on. It should look like ["account1", "account2"]. If you want just one account, no comma needed. | ||
TWITTER_SOURCE_ACCOUNTS = [""] # A list of comma-separated, quote-enclosed Twitter handles of account that you'll generate tweets based on. It should look like ["account1", "account2"]. If you want just one account, no comma needed. | ||
MASTODON_SOURCE_ACCOUNTS = [""] # A list, e.g. ["@[email protected]"] | ||
SOURCE_EXCLUDE = r'^$' # Source tweets that match this regexp will not be added to the Markov chain. You might want to filter out inappropriate words for example. | ||
STATIC_TEST = False # Set this to True if you want to test Markov generation from a static file instead of the API. | ||
TEST_SOURCE = ".txt" # The name of a text file of a string-ified list for testing. To avoid unnecessarily hitting Twitter API. You can use the included testcorpus.txt, if needed. | ||
|
@@ -22,4 +33,4 @@ | |
ORDER = 2 # How closely do you want this to hew to sensical? 2 is low and 4 is high. | ||
|
||
DEBUG = True # Set this to False to start Tweeting live | ||
TWEET_ACCOUNT = "" # The name of the account you're tweeting to. | ||
TWEET_ACCOUNT = "" # The name of the account you're tweeting to. |
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,2 +1,3 @@ | ||
python-twitter | ||
Mastodon.py | ||
beautifulsoup4 |