Skip to content

Commit

Permalink
account name via -a flag now. should not be needed
Browse files Browse the repository at this point in the history
  • Loading branch information
mahtin committed Nov 26, 2023
1 parent 3621a4d commit c88bbfa
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 10 deletions.
21 changes: 16 additions & 5 deletions examples/example_ai_images.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ def doit(account_name, prompt_text):
cf = CloudFlare.CloudFlare(global_request_timeout=120)

try:
params = {'name': account_name, 'per_page': 1}
if account_name == None or account_name == '':
params = {'per_page': 1}
else:
params = {'name': account_name, 'per_page': 1}
accounts = cf.accounts.get(params=params)
except CloudFlare.exceptions.CloudFlareAPIError as e:
exit('/accounts %d %s - api call failed' % (e, e))

account_id = accounts[0]['id']
try:
account_id = accounts[0]['id']
except IndexError:
exit('%s: account name not found' % (account_name))

image_create_data = {
'prompt': prompt_text,
Expand All @@ -45,9 +51,14 @@ def doit(account_name, prompt_text):
sys.stdout.buffer.write(r)

def main():
account_name = sys.argv[1]
if len(sys.argv) > 2:
prompt_text = ' '.join(sys.argv[2:])
if sys.argv[1] == '-a':
del sys.argv[1]
account_name = sys.argv[1]
del sys.argv[1]
else:
account_name = None
if len(sys.argv) > 1:
prompt_text = ' '.join(sys.argv[1:])
else:
prompt_text = "A happy llama running through an orange cloud"
doit(account_name, prompt_text)
Expand Down
21 changes: 16 additions & 5 deletions examples/example_ai_translate.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,18 @@ def doit(account_name, english_text):
cf = CloudFlare.CloudFlare(global_request_timeout=120)

try:
params = {'name': account_name, 'per_page': 1}
if account_name == None or account_name == '':
params = {'per_page': 1}
else:
params = {'name': account_name, 'per_page': 1}
accounts = cf.accounts.get(params=params)
except CloudFlare.exceptions.CloudFlareAPIError as e:
exit('/accounts %d %s - api call failed' % (e, e))

account_id = accounts[0]['id']
try:
account_id = accounts[0]['id']
except IndexError:
exit('%s: account name not found' % (account_name))

translate_data = {
'text': english_text,
Expand All @@ -47,9 +53,14 @@ def doit(account_name, english_text):
print(r['translated_text'])

def main():
account_name = sys.argv[1]
if len(sys.argv) > 2:
english_text = ' '.join(sys.argv[2:])
if sys.argv[1] == '-a':
del sys.argv[1]
account_name = sys.argv[1]
del sys.argv[1]
else:
account_name = None
if len(sys.argv) > 1:
english_text = ' '.join(sys.argv[1:])
else:
english_text = "I'll have an order of the moule frites"
doit(account_name, english_text)
Expand Down

0 comments on commit c88bbfa

Please sign in to comment.