Update 06/12/2020
* Added new configuration options, please update your twitter.json after updating! Please see ./etc/twitter.json for changes. * The hashtag list can now act as block list or include list, depending on `is_blocklist` * Replies can now be ignored by setting `omit_replies` to true.
This commit is contained in:
parent
ee6a28f17c
commit
b252f8855b
13
README.md
13
README.md
@ -33,10 +33,12 @@ Next, you will need to install the configuration files below:
|
|||||||
"bearer": "bearer token of your twitter app",
|
"bearer": "bearer token of your twitter app",
|
||||||
"twitter-handle": "twitter handle",
|
"twitter-handle": "twitter handle",
|
||||||
"output-location": "/hugo/project/directory/data/latest_tweet.json",
|
"output-location": "/hugo/project/directory/data/latest_tweet.json",
|
||||||
"exclude": [
|
"is_blocklist": true,
|
||||||
|
"hashtags": [
|
||||||
"dontincludethishastag",
|
"dontincludethishastag",
|
||||||
"politics"
|
"politics"
|
||||||
]
|
],
|
||||||
|
"omit_replies": true
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
@ -125,14 +127,19 @@ to the footer.
|
|||||||
|
|
||||||
## Excluding hashtags
|
## Excluding hashtags
|
||||||
|
|
||||||
Sometimes you do not want a tweet to decorate the hard work you call your web home. You can edit the following in `twitter.json` to exclude certain hashtags:
|
Sometimes you do not want a tweet to decorate the hard work you call your web home.
|
||||||
|
You can edit the following in `twitter.json` to exclude certain hashtags:
|
||||||
|
|
||||||
```
|
```
|
||||||
|
"is_blocklist: true,
|
||||||
"exclude": [
|
"exclude": [
|
||||||
"politics"
|
"politics"
|
||||||
]
|
]
|
||||||
```
|
```
|
||||||
|
|
||||||
|
**Note**: If `is_blocklist` is false, then it acts as a list of allowed hashtags and will only output new json
|
||||||
|
if the hashtag is found.
|
||||||
|
|
||||||
You find sample configuration files in the `/etc/` folder in the project root.
|
You find sample configuration files in the `/etc/` folder in the project root.
|
||||||
|
|
||||||
<!--suppress HtmlDeprecatedAttribute -->
|
<!--suppress HtmlDeprecatedAttribute -->
|
||||||
|
@ -1,7 +1,11 @@
|
|||||||
{
|
{
|
||||||
"bearer": "bearer token from twitter",
|
"bearer": "bearer token of your twitter app",
|
||||||
"twitter-handle": "GothSeiDank",
|
"twitter-handle": "twitter handle",
|
||||||
"output-location": "/path/to/hugo/data/latest_tweet.json",
|
"output-location": "/hugo/project/directory/data/latest_tweet.json",
|
||||||
"exclude": ["1", "2"]
|
"is_blocklist": true,
|
||||||
|
"hashtags": [
|
||||||
|
"dontincludethishastag",
|
||||||
|
"politics"
|
||||||
|
],
|
||||||
|
"omit_replies": true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,9 +52,21 @@ class twitter:
|
|||||||
r = requests.get(url=get_url, headers=header)
|
r = requests.get(url=get_url, headers=header)
|
||||||
r.raise_for_status()
|
r.raise_for_status()
|
||||||
try:
|
try:
|
||||||
excluded = r.json()[0]['entities']['hashtags'][0]['text']
|
# Get hashtag list
|
||||||
if excluded in self.credentials['exclude']:
|
hashtag = r.json()[0]['entities']['hashtags'][0]['text']
|
||||||
|
|
||||||
|
# It's a blocklist and the hashtag is found
|
||||||
|
if self.credentials['is_blocklist'] and hashtag in self.credentials['hashtags']:
|
||||||
exit(0)
|
exit(0)
|
||||||
|
|
||||||
|
# It is a list of allowed hashtags and the hashtag was not found
|
||||||
|
if not self.credentials['is_blocklist'] and hashtag not in self.credentials['hashtags']:
|
||||||
|
exit(0)
|
||||||
|
|
||||||
|
if self.credentials['omit_replies'] and r.json()[0]['in_reply_to_status_id']:
|
||||||
|
# Tweet is a reply
|
||||||
|
exit(0)
|
||||||
|
|
||||||
except IndexError:
|
except IndexError:
|
||||||
# No hashtags, that's fine
|
# No hashtags, that's fine
|
||||||
pass
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user