setup twitter credentials management
This commit is contained in:
@@ -1,4 +0,0 @@
|
|||||||
[Credentials]
|
|
||||||
api_key: xxx
|
|
||||||
api_secret: yyy
|
|
||||||
bearer_token: zzz
|
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
# Twitter developer credentials.
|
||||||
|
# MAKE SURE USED VALUES AREN'T UPLOADED TO THE REPO!
|
||||||
|
#
|
||||||
|
# This file should be added to .gitignore as a safeguard.
|
||||||
|
|
||||||
|
[Credentials]
|
||||||
|
api_key='xxx'
|
||||||
|
api_secret='yyy'
|
||||||
|
bearer_token='zzz'
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import os
|
||||||
|
import configparser
|
||||||
|
|
||||||
|
# returns dictionary of the Credentials section.
|
||||||
|
# NOT TO BE USED OUTSIDE OF THIS FILE.
|
||||||
|
def get_ini_credentials():
|
||||||
|
c = configparser.ConfigParser()
|
||||||
|
if len(c.read(os.path.join(os.path.dirname(__file__), os.pardir, 'secrets.ini'))) > 0 and c.has_section('Credentials'):
|
||||||
|
return c['Credentials']
|
||||||
|
return None
|
||||||
|
|
||||||
|
# returns the api_key stored in secrets.ini
|
||||||
|
def api_key():
|
||||||
|
c = get_ini_credentials()
|
||||||
|
return c.get(option='api_key', fallback='xxx') if c is not None else 'xxx'
|
||||||
|
|
||||||
|
# returns the api_secret stored in secrets.ini
|
||||||
|
def api_secret():
|
||||||
|
c = get_ini_credentials()
|
||||||
|
return c.get(option='api_secret', fallback='yyy') if c is not None else 'yyy'
|
||||||
|
|
||||||
|
# returns the bearer_token stored in secrets.ini
|
||||||
|
def bearer_token():
|
||||||
|
c = get_ini_credentials()
|
||||||
|
return c.get(option='bearer_token', fallback='xxx') if c is not None else 'zzz'
|
||||||
|
|
||||||
|
# print(api_key())
|
||||||
|
# print(api_secret())
|
||||||
|
# print(bearer_token())
|
||||||
Reference in New Issue
Block a user