本文整理汇总了Python中config.USERNAME属性的典型用法代码示例。如果您正苦于以下问题:Python config.USERNAME属性的具体用法?Python config.USERNAME怎么用?Python config.USERNAME使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类config
的用法示例。
在下文中一共展示了config.USERNAME属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_credentials
# 需要导入模块: import config [as 别名]
# 或者: from config import USERNAME [as 别名]
def get_credentials(database):
settings = database.settings
creds = settings.get_credentials()
if creds == (USERNAME, PASSWORD):
return creds
elif creds is not None and (USERNAME is None or PASSWORD is None):
return creds
elif creds is not None and USERNAME is not None and PASSWORD is not None:
settings.set_credentials(USERNAME, PASSWORD)
return (USERNAME, PASSWORD)
elif creds is None and (USERNAME is None or PASSWORD is None):
username = base64.b64encode(sha256(str(random.getrandbits(255))).digest())[:20]
password = base64.b64encode(sha256(str(random.getrandbits(255))).digest())[:20]
settings.set_credentials(username, password)
return (username, password)
elif creds is None and (USERNAME is not None and PASSWORD is not None):
settings.set_credentials(USERNAME, PASSWORD)
return (USERNAME, PASSWORD)
示例2: start
# 需要导入模块: import config [as 别名]
# 或者: from config import USERNAME [as 别名]
def start():
"""Start the sneakpeek application."""
logging.info("Starting application")
logging.info("Instantiating Reddit instance")
reddit = praw.Reddit(
client_id=config.CLIENT["ID"],
client_secret=config.CLIENT["SECRET"],
user_agent=config.USER_AGENT,
username=config.USERNAME,
password=config.PASSWORD)
try:
scan(reddit.subreddit(config.SUBREDDIT))
except Exception as exception:
# This should never happen,
# because it breaks the infinite subreddit monitoring
# provided by subreddit.stream.submissions()
logging.critical("Exception occurred while scanning. This should never happen.")
logging.critical(exception)
示例3: __init__
# 需要导入模块: import config [as 别名]
# 或者: from config import USERNAME [as 别名]
def __init__(self, local=True):
if local:
# Class instance connection to Mongo
self.connection = MongoClient()
if config.AUTH:
try:
self.connection.admin.authenticate(config.USERNAME, config.PASSWORD)
except:
print('Error: Authentication failed. Please check:\n1. MongoDB credentials in config.py\n2. MongoDB uses the correct authentication schema (MONGODB-CR)\nFor more info. see https://github.com/bitslabsyr/stack/wiki/Installation')
sys.exit(1)
# App-wide config file for project info access
self.config_db = self.connection.config
self.stack_config = self.config_db.config
else:
self.connection = MongoClient(config.CT_SERVER)
if config.CT_AUTH:
try:
self.connection.admin.authenticate(config.CT_USERNAME, config.CT_PASSWORD)
except:
print('Error: Authentication failed at the central server. Please check:\n1. MongoDB credentials in config.py\n2. MongoDB uses the correct authentication schema (MONGODB-CR)\nFor more info. see https://github.com/bitslabsyr/stack/wiki/Installation')
sys.exit(1)
示例4: main
# 需要导入模块: import config [as 别名]
# 或者: from config import USERNAME [as 别名]
def main():
sdk = SDK(APP_KEY, APP_SECRET, SERVER)
platform = sdk.platform()
platform.login(USERNAME, EXTENSION, PASSWORD)
# Simple GET
response = platform.get('/account/~/extension/~')
user = response.json()
user_id = str(user.id)
print('User loaded ' + user.name + ' (' + user_id + ')')
print('Headers ' + str(response.response().headers))
print(type(response.response()._content))
# Multipart response
try:
multipart_response = platform.get('/account/~/extension/' + user_id + ',' + user_id + '/presence').multipart()
print('Multipart 1\n' + str(multipart_response[0].json_dict()))
print('Multipart 2\n' + str(multipart_response[1].json_dict()))
except ApiException as e:
print('Cannot load multipart')
print('URL ' + e.api_response().request().url)
print('Response' + str(e.api_response().json()))
示例5: main
# 需要导入模块: import config [as 别名]
# 或者: from config import USERNAME [as 别名]
def main():
cache = get_file_cache()
# Create SDK instance
sdk = SDK(APP_KEY, APP_SECRET, SERVER)
platform = sdk.platform()
# Set cached authentication data
platform.auth().set_data(cache)
try:
platform.is_authorized()
print('Authorized already by cached data')
except Exception as e:
platform.login(USERNAME, EXTENSION, PASSWORD)
print('Authorized by credentials')
# Perform refresh by force
platform.refresh()
print('Refreshed')
set_file_cache(platform.auth().data())
print("Authentication data has been cached")
示例6: gen_feed
# 需要导入模块: import config [as 别名]
# 或者: from config import USERNAME [as 别名]
def gen_feed():
fg = FeedGenerator()
fg.id(f"{ID}")
fg.title(f"{USERNAME} notes")
fg.author({"name": USERNAME})
fg.link(href=ID, rel="alternate")
fg.description(f"{USERNAME} notes")
fg.logo(ME.get("icon", {}).get("url"))
fg.language("en")
for item in DB.activities.find(
{
"box": Box.OUTBOX.value,
"type": "Create",
"meta.deleted": False,
"meta.public": True,
},
limit=10,
).sort("_id", -1):
fe = fg.add_entry()
fe.id(item["activity"]["object"].get("url"))
fe.link(href=item["activity"]["object"].get("url"))
fe.title(item["activity"]["object"]["content"])
fe.description(item["activity"]["object"]["content"])
return fg
示例7: work
# 需要导入模块: import config [as 别名]
# 或者: from config import USERNAME [as 别名]
def work():
"""Main method executing the script.
It connects to an account, loads dictionaries from proper files (declared in config file).
Afterwards it executes process_comments method with proper arguments passed.
"""
reddit = account.get_account()
logger.info('Connected to Reddit account : ' + config.USERNAME)
comment_stream = reddit.subreddit(config.SUBREDDIT).stream.comments(pause_after=-1)
submission_stream = reddit.subreddit(config.SUBREDDIT).stream.submissions(pause_after=-1)
while True:
for comment in comment_stream:
if comment is None:
break
process_replyable(reddit, comment)
for submission in submission_stream:
if submission is None:
break
process_replyable(reddit, submission)
示例8: setUpClass
# 需要导入模块: import config [as 别名]
# 或者: from config import USERNAME [as 别名]
def setUpClass(self):
self.api_base_url = config.BASE_URL or 'http://api.dailymotion.com'
self.api_key = config.CLIENT_ID
self.api_secret = config.CLIENT_SECRET
self.username = config.USERNAME
self.password = config.PASSWORD
self.scope = ['manage_videos', 'manage_playlists', 'userinfo']
self.redirect_uri = config.REDIRECT_URI
self.oauth_authorize_endpoint_url = config.OAUTH_AUTHORIZE_URL or 'https://api.dailymotion.com/oauth/authorize'
self.oauth_token_endpoint_url = config.OAUTH_TOKEN_URL or 'https://api.dailymotion.com/oauth/token'
self.session_file_directory = './data'
if not os.path.exists(self.session_file_directory):
os.makedirs(self.session_file_directory)
示例9: main
# 需要导入模块: import config [as 别名]
# 或者: from config import USERNAME [as 别名]
def main():
sdk = SDK(APP_KEY, APP_SECRET, SERVER)
platform = sdk.platform()
platform.login(USERNAME, EXTENSION, PASSWORD)
def on_message(msg):
print(msg)
def pubnub():
try:
s = sdk.create_subscription()
s.add_events(['/account/~/extension/~/message-store'])
s.on(Events.notification, on_message)
s.register()
while True:
sleep(0.1)
except KeyboardInterrupt:
print("Pubnub listener stopped...")
p = Process(target=pubnub)
try:
p.start()
except KeyboardInterrupt:
p.terminate()
print("Stopped by User")
print("Wait for notification...")
示例10: main
# 需要导入模块: import config [as 别名]
# 或者: from config import USERNAME [as 别名]
def main():
sdk = SDK(APP_KEY, APP_SECRET, SERVER)
platform = sdk.platform()
platform.login(USERNAME, EXTENSION, PASSWORD)
to_numbers = "1234567890"
params = {'from': {'phoneNumber': USERNAME},'to': [{'phoneNumber': to_number}],'text': "SMS message"}
response = platform.post('/restapi/v1.0/account/~/extension/~/sms', params)
print 'Sent SMS: ' + response.json().uri
示例11: main
# 需要导入模块: import config [as 别名]
# 或者: from config import USERNAME [as 别名]
def main():
sdk = SDK(APP_KEY, APP_SECRET, SERVER)
platform = sdk.platform()
platform.login(USERNAME, EXTENSION, PASSWORD)
# Step 1. Get MMS-enabled phone number
phone_numbers = platform.get('/account/~/extension/~/phone-number', {'perPage': 'max'}).json().records
mms_number = None
for phone_number in phone_numbers:
if 'MmsSender' in phone_number.features:
mms_number = phone_number.phoneNumber
print 'MMS Phone Number: ' + mms_number
# Step 2. Send MMS
attachment = (
'test.png',
urllib.urlopen('https://developers.ringcentral.com/assets/images/ico_case_crm.png').read(),
'image/png'
)
builder = sdk.create_multipart_builder()
builder.set_body({
'from': {'phoneNumber': mms_number},
'to': [{'phoneNumber': MOBILE}],
'text': 'MMS from Python' # this is optional
})
builder.add(attachment)
request = builder.request('/account/~/extension/~/sms')
response = platform.send_request(request)
print 'Sent MMS: ' + response.json().uri
示例12: wellknown_webfinger
# 需要导入模块: import config [as 别名]
# 或者: from config import USERNAME [as 别名]
def wellknown_webfinger() -> Any:
"""Exposes/servers WebFinger data."""
resource = request.args.get("resource")
if resource not in [f"acct:{config.USERNAME}@{config.DOMAIN}", config.ID]:
abort(404)
out = {
"subject": f"acct:{config.USERNAME}@{config.DOMAIN}",
"aliases": [config.ID],
"links": [
{
"rel": "http://webfinger.net/rel/profile-page",
"type": "text/html",
"href": config.ID,
},
{"rel": "self", "type": "application/activity+json", "href": config.ID},
{
"rel": "http://ostatus.org/schema/1.0/subscribe",
"template": config.BASE_URL + "/authorize_follow?profile={uri}",
},
{"rel": "magic-public-key", "href": config.KEY.to_magic_key()},
{
"href": config.ICON_URL,
"rel": "http://webfinger.net/rel/avatar",
"type": mimetypes.guess_type(config.ICON_URL)[0],
},
],
}
return jsonify(out, "application/jrd+json; charset=utf-8")
示例13: nodeinfo
# 需要导入模块: import config [as 别名]
# 或者: from config import USERNAME [as 别名]
def nodeinfo() -> Any:
"""NodeInfo endpoint."""
q = {
"box": Box.OUTBOX.value,
"meta.deleted": False,
"type": {"$in": [ap.ActivityType.CREATE.value, ap.ActivityType.ANNOUNCE.value]},
}
out = {
"version": "2.1",
"software": {
"name": "microblogpub",
"version": config.VERSION,
"repository": "https://github.com/tsileo/microblog.pub",
},
"protocols": ["activitypub"],
"services": {"inbound": [], "outbound": []},
"openRegistrations": False,
"usage": {"users": {"total": 1}, "localPosts": DB.activities.count(q)},
"metadata": {
"nodeName": f"@{config.USERNAME}@{config.DOMAIN}",
"version": config.VERSION,
"versionDate": config.VERSION_DATE,
},
}
return jsonify(
out,
"application/json; profile=http://nodeinfo.diaspora.software/ns/schema/2.1#",
)
示例14: json_feed
# 需要导入模块: import config [as 别名]
# 或者: from config import USERNAME [as 别名]
def json_feed(path: str) -> Dict[str, Any]:
"""JSON Feed (https://jsonfeed.org/) document."""
data = []
for item in DB.activities.find(
{
"box": Box.OUTBOX.value,
"type": "Create",
"meta.deleted": False,
"meta.public": True,
},
limit=10,
).sort("_id", -1):
data.append(
{
"id": item["activity"]["id"],
"url": item["activity"]["object"].get("url"),
"content_html": item["activity"]["object"]["content"],
"content_text": html2text(item["activity"]["object"]["content"]),
"date_published": item["activity"]["object"].get("published"),
}
)
return {
"version": "https://jsonfeed.org/version/1",
"user_comment": (
"This is a microblog feed. You can add this to your feed reader using the following URL: "
+ ID
+ path
),
"title": USERNAME,
"home_page_url": ID,
"feed_url": ID + path,
"author": {
"name": USERNAME,
"url": ID,
"avatar": ME.get("icon", {}).get("url"),
},
"items": data,
}
示例15: test_account
# 需要导入模块: import config [as 别名]
# 或者: from config import USERNAME [as 别名]
def test_account(self):
"""Method used to test the Reddit instance returned by get_account()
"""
reddit = account.get_account()
self.assertEqual(reddit.user.me(), config.USERNAME)