This repository has been archived by the owner on Oct 11, 2022. It is now read-only.
forked from sscheetz/etsy-python2
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_v2.py
executable file
·86 lines (69 loc) · 2.8 KB
/
test_v2.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/usr/bin/env python
import os, sys
import oauth2 as oauth
import webbrowser
from etsy2 import Etsy, EtsyEnvProduction
from .oauth import EtsyOAuthClient
logging_enabled = True
etsy_env = EtsyEnvProduction()
def my_log(msg):
if logging_enabled: print(msg)
def write_config_file(oauth_token):
os.umask(0o077)
config_file = open('config.py', 'w')
if config:
config_file.write("oauth_consumer_key = %r\n" % config.oauth_consumer_key)
config_file.write("oauth_consumer_secret = %r\n" % config.oauth_consumer_secret)
if oauth_token:
config_file.write("oauth_token_key = %r\n" % oauth_token.key)
config_file.write("oauth_token_secret = %r\n" % oauth_token.secret)
try:
import config
except ImportError:
config = None
write_config_file(oauth_token=None)
if hasattr(config, 'oauth_consumer_key') and hasattr(config, 'oauth_consumer_secret'):
oauth_client = EtsyOAuthClient(
oauth_consumer_key=config.oauth_consumer_key,
oauth_consumer_secret=config.oauth_consumer_secret,
etsy_env=etsy_env)
else:
sys.stderr.write('ERROR: You must set oauth_consumer_key and oauth_consumer_secret in config.py\n')
sys.exit(1)
if hasattr(config, 'oauth_token_key') and hasattr(config, 'oauth_token_secret'):
oauth_client.token = oauth.Token(
key=config.oauth_token_key,
secret=config.oauth_token_secret)
else:
webbrowser.open(oauth_client.get_signin_url())
oauth_client.set_oauth_verifier(input('Enter OAuth verifier: '))
write_config_file(oauth_client.token)
etsy_api = Etsy(etsy_oauth_client=oauth_client, etsy_env=etsy_env, log=my_log)
# print 'oauth access token: (key=%r; secret=%r)' % (oauth_client.token.key, oauth_client.token.secret)
print('findAllShopListingsActive => %r' % etsy_api.findAllShopListingsActive(shop_id=config.user_id, sort_on='created', limit=1))
# print('getListing => %r' % etsy_api.getListing(listing_id=63067548))
print('findAllUserShippingTemplates => %r' % etsy_api.findAllUserShippingTemplates(user_id=config.user_id))
# TODO write UPDATE/INSERT test that doesnt cost money
# TODO write test that excerises boolean param types
#def testCreateListing():
# print("Creating listing...")
#
# result = etsy_api.createListing(
# description=config.description,
# title=config.title,
# price=config.price,
# tags=config.tags,
# materials=config.materials,
# shipping_template_id=config.shipping_template_id,
# shop_section_id=config.shop_section_id,
# quantity=config.quantity)
#
# listing_id = result[0]['listing_id']
#
# print("Created listing with listing id %d" % listing_id)
#
# result = etsy_api.uploadListingImage(listing_id=listing_id, image=config.image_file)
#
# print("Result of uploading image: %r" % result)
#
#testCreateListing()