move credentials to .env
This commit is contained in:
@@ -5,6 +5,22 @@ Twitter bot that tracks cross-company interactions between the non-JP branches o
|
|||||||
|
|
||||||
**This project was created to run [this account](https://twitter.com/NijiHolo_EN_ID).**
|
**This project was created to run [this account](https://twitter.com/NijiHolo_EN_ID).**
|
||||||
|
|
||||||
|
## `.env`
|
||||||
|
These need to be defined in a `.env` file at the project root (outside of `src`):
|
||||||
|
```
|
||||||
|
# Scweet (scraping)
|
||||||
|
SCWEET_EMAIL=
|
||||||
|
SCWEET_USERNAME=
|
||||||
|
SCWEET_PASSWORD=
|
||||||
|
|
||||||
|
# Twitter API bot keys (posting)
|
||||||
|
api_key=
|
||||||
|
api_secret=
|
||||||
|
oauth1_access_token=
|
||||||
|
oauth1_access_secret=
|
||||||
|
bearer_token=
|
||||||
|
```
|
||||||
|
|
||||||
## Running modes
|
## Running modes
|
||||||
The bot may run in these modes:
|
The bot may run in these modes:
|
||||||
* Catch-up (`c`): intended to run only once, scan all accounts for cross-company tweets and post them. Terminate when done posting all.
|
* Catch-up (`c`): intended to run only once, scan all accounts for cross-company tweets and post them. Terminate when done posting all.
|
||||||
|
|||||||
+2
-2
@@ -1,6 +1,6 @@
|
|||||||
|
python-dotenv
|
||||||
nest-asyncio
|
nest-asyncio
|
||||||
pytz
|
pytz
|
||||||
|
Scweet
|
||||||
tweet-capture
|
tweet-capture
|
||||||
tweepy
|
|
||||||
opencv-python
|
opencv-python
|
||||||
git+https://github.com/muskit/twint_2022_fix.git
|
|
||||||
-23
@@ -1,23 +0,0 @@
|
|||||||
## Twitter developer credentials.
|
|
||||||
|
|
||||||
# ---->> MAKE SURE YOUR VALUES AREN'T UPLOADED TO THE REPO! <<----
|
|
||||||
#
|
|
||||||
# This file should be added to .gitignore as a safeguard.
|
|
||||||
#
|
|
||||||
# If Git still wants to commit this file after changing its contents,
|
|
||||||
# force Git to stop tracking the file's changes:
|
|
||||||
# git update-index --assume-unchanged [<file> ...]
|
|
||||||
#
|
|
||||||
# To resume tracking its changes:
|
|
||||||
# git update-index --no-assume-unchanged [<file> ...]
|
|
||||||
#
|
|
||||||
# https://stackoverflow.com/questions/10755655/git-ignore-tracked-files
|
|
||||||
|
|
||||||
# note: api_key/secret = consumer_key/secret
|
|
||||||
|
|
||||||
[Credentials]
|
|
||||||
api_key=xxx
|
|
||||||
api_secret=yyy
|
|
||||||
bearer_token=zzz
|
|
||||||
oauth1_access_token=x
|
|
||||||
oauth1_access_secret=y
|
|
||||||
+11
-11
@@ -1,41 +1,41 @@
|
|||||||
## Twitter developer credentials management.
|
## Twitter developer credentials management.
|
||||||
|
|
||||||
import os
|
from os.path import join, isfile
|
||||||
import configparser
|
from dotenv import dotenv_values
|
||||||
|
|
||||||
import util
|
import util
|
||||||
|
|
||||||
# returns dictionary of the Credentials section.
|
# returns dictionary of the Credentials section.
|
||||||
# [NOT TO BE USED OUTSIDE OF THIS FILE.]
|
# [NOT TO BE USED OUTSIDE OF THIS FILE.]
|
||||||
def __get_ini_credentials():
|
def __get_env():
|
||||||
c = configparser.RawConfigParser()
|
f = join(util.get_project_dir(), '.env')
|
||||||
if len(c.read(os.path.join(util.get_project_dir(), 'secrets.ini'))) > 0 and c.has_section('Credentials'):
|
if isfile(f):
|
||||||
return c['Credentials']
|
return dotenv_values(f)
|
||||||
return None
|
return None
|
||||||
|
|
||||||
# returns the consumer api_key stored in secrets.ini
|
# returns the consumer api_key stored in secrets.ini
|
||||||
def api_key():
|
def api_key():
|
||||||
c = __get_ini_credentials()
|
c = __get_env()
|
||||||
return c.get(option='api_key', fallback='xxx') if c is not None else 'xxx'
|
return c.get(option='api_key', fallback='xxx') if c is not None else 'xxx'
|
||||||
|
|
||||||
# returns the consumer api_secret stored in secrets.ini
|
# returns the consumer api_secret stored in secrets.ini
|
||||||
def api_secret():
|
def api_secret():
|
||||||
c = __get_ini_credentials()
|
c = __get_env()
|
||||||
return c.get(option='api_secret', fallback='yyy') if c is not None else 'yyy'
|
return c.get(option='api_secret', fallback='yyy') if c is not None else 'yyy'
|
||||||
|
|
||||||
# returns the bearer_token stored in secrets.ini
|
# returns the bearer_token stored in secrets.ini
|
||||||
def bearer_token():
|
def bearer_token():
|
||||||
c = __get_ini_credentials()
|
c = __get_env()
|
||||||
return c.get(option='bearer_token', fallback='zzz') if c is not None else 'zzz'
|
return c.get(option='bearer_token', fallback='zzz') if c is not None else 'zzz'
|
||||||
|
|
||||||
# returns the access_token stroed in secrets.ini
|
# returns the access_token stroed in secrets.ini
|
||||||
def access_token():
|
def access_token():
|
||||||
c = __get_ini_credentials()
|
c = __get_env()
|
||||||
return c.get(option='oauth1_access_token', fallback='zzz') if c is not None else 'aaa'
|
return c.get(option='oauth1_access_token', fallback='zzz') if c is not None else 'aaa'
|
||||||
|
|
||||||
# returns the access_secret stroed in secrets.ini
|
# returns the access_secret stroed in secrets.ini
|
||||||
def access_secret():
|
def access_secret():
|
||||||
c = __get_ini_credentials()
|
c = __get_env()
|
||||||
return c.get(option='oauth1_access_secret', fallback='zzz') if c is not None else 'bbb'
|
return c.get(option='oauth1_access_secret', fallback='zzz') if c is not None else 'bbb'
|
||||||
|
|
||||||
def get_all_secrets():
|
def get_all_secrets():
|
||||||
|
|||||||
Reference in New Issue
Block a user