Skip to content
This repository was archived by the owner on Nov 22, 2024. It is now read-only.

Commit c88bbfa

Browse files
committed
account name via -a flag now. should not be needed
1 parent 3621a4d commit c88bbfa

File tree

2 files changed

+32
-10
lines changed

2 files changed

+32
-10
lines changed

examples/example_ai_images.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ def doit(account_name, prompt_text):
2323
cf = CloudFlare.CloudFlare(global_request_timeout=120)
2424

2525
try:
26-
params = {'name': account_name, 'per_page': 1}
26+
if account_name == None or account_name == '':
27+
params = {'per_page': 1}
28+
else:
29+
params = {'name': account_name, 'per_page': 1}
2730
accounts = cf.accounts.get(params=params)
2831
except CloudFlare.exceptions.CloudFlareAPIError as e:
2932
exit('/accounts %d %s - api call failed' % (e, e))
3033

31-
account_id = accounts[0]['id']
34+
try:
35+
account_id = accounts[0]['id']
36+
except IndexError:
37+
exit('%s: account name not found' % (account_name))
3238

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

4753
def main():
48-
account_name = sys.argv[1]
49-
if len(sys.argv) > 2:
50-
prompt_text = ' '.join(sys.argv[2:])
54+
if sys.argv[1] == '-a':
55+
del sys.argv[1]
56+
account_name = sys.argv[1]
57+
del sys.argv[1]
58+
else:
59+
account_name = None
60+
if len(sys.argv) > 1:
61+
prompt_text = ' '.join(sys.argv[1:])
5162
else:
5263
prompt_text = "A happy llama running through an orange cloud"
5364
doit(account_name, prompt_text)

examples/example_ai_translate.py

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,18 @@ def doit(account_name, english_text):
2323
cf = CloudFlare.CloudFlare(global_request_timeout=120)
2424

2525
try:
26-
params = {'name': account_name, 'per_page': 1}
26+
if account_name == None or account_name == '':
27+
params = {'per_page': 1}
28+
else:
29+
params = {'name': account_name, 'per_page': 1}
2730
accounts = cf.accounts.get(params=params)
2831
except CloudFlare.exceptions.CloudFlareAPIError as e:
2932
exit('/accounts %d %s - api call failed' % (e, e))
3033

31-
account_id = accounts[0]['id']
34+
try:
35+
account_id = accounts[0]['id']
36+
except IndexError:
37+
exit('%s: account name not found' % (account_name))
3238

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

4955
def main():
50-
account_name = sys.argv[1]
51-
if len(sys.argv) > 2:
52-
english_text = ' '.join(sys.argv[2:])
56+
if sys.argv[1] == '-a':
57+
del sys.argv[1]
58+
account_name = sys.argv[1]
59+
del sys.argv[1]
60+
else:
61+
account_name = None
62+
if len(sys.argv) > 1:
63+
english_text = ' '.join(sys.argv[1:])
5364
else:
5465
english_text = "I'll have an order of the moule frites"
5566
doit(account_name, english_text)

0 commit comments

Comments
 (0)