コード例 #1
0
ファイル: utils.py プロジェクト: broxeph/ameryn
def print_order_notes(item_list):
    # items.csv item notes
    notes_lines = [' - items.csv -']
    for item in [item for item in item_list if not item.copy_counter and not item.side]:
        if item.customer_notes:
            notes_lines.append('{0} - Customer notes: {1}'.format(item.name, item.customer_notes))

    # WooCommerce order notes
    notes_lines.append(' - WC notes -')
    wc_client = WooCommerceClient(config.wc_ck, config.wc_cs, config.base_url, oauth_enabled=False)
    for order_id in set([item.order.lstrip('0') for item in item_list]):
        order = wc_client.get_order(order_id)['order']
        html_parser = HTMLParser.HTMLParser()
        notes_lines.append('{0} - {1}'.format(order_id, html_parser.unescape(order['note'])))

    # Print notes; write to text file
    for notes_line in notes_lines:
        print notes_line
    order_notes_file = os.path.join(config.order_notes_path, 'order_notes.txt')
    with open(order_notes_file, 'w') as notes:
        for notes_line in notes_lines:
            notes.write(notes_line + '\n')

    # Open notes in default text editor
    os.startfile(order_notes_file)
コード例 #2
0
ファイル: order.py プロジェクト: broxeph/ameryn
def print_order_notes(item_list=None, refresh_csv=True):
    if not item_list:
        # Input whole Tracked folder
        item_list = [Item(each_file) for each_file in os.listdir(config.tracked_folder) if os.path.splitext(each_file)[-1] == '.wav']

    if refresh_csv:
        utils.export_csv('Items') # Grab spreadsheet from Google Drive

    # items.csv item notes
    notes_lines = [' - items.csv -']
    for item in [item for item in item_list if not item.copy_counter and not item.side]:
        if item.customer_notes:
            notes_lines.append('{0} - Customer notes: {1}'.format(item.name, item.customer_notes))
        if item.private_notes and len(item.private_notes) > 3:
            notes_lines.append('{0} - Private notes: {1}'.format(item.name, item.private_notes))

    # WooCommerce order notes
    notes_lines.append(' - WC notes -')
    wc_client = WooCommerceClient(config.wc_ck, config.wc_cs, config.base_url, oauth_enabled=False)
    for order_id in set([item.order.lstrip('0') for item in item_list]):
        order = wc_client.get_order(order_id)['order']
        html_parser = HTMLParser.HTMLParser()
        notes_lines.append('{0} - {1}'.format(order_id, html_parser.unescape(order['note'])))

    # Print notes; write to text file
    for notes_line in notes_lines:
        print notes_line
    order_notes_file = os.path.join(config.order_notes_folder, 'order_notes.txt')
    with open(order_notes_file, 'w') as notes:
        for notes_line in notes_lines:
            notes.write(notes_line + '\n')

    # Open notes in default text editor
    os.startfile(order_notes_file)
コード例 #3
0
ファイル: dbox-test.py プロジェクト: broxeph/ameryn
def send_dbox_email(order_id, wc_client=None, dbox_client=None, smtp_server=None):
    # Check if Dropbox folder exists
    dbox_order_path = path.join(dbox_path, order_id)
    if not path.isdir(dbox_order_path):
        print 'No Dropbox folder found for order #{0} at {1}.'.format(order_id, dbox_order_path)
        return

    if not wc_client: wc_client = WooCommerceClient(wc_ck, wc_cs, base_url, oauth_enabled=False)
    order = wc_client.get_order(order_id)['order']

    # Get variables
    cust_email = order['customer']['billing_address']['email']
    first_name = order['billing_address']['first_name'].capitalize()
    last_name = order['billing_address']['last_name'].capitalize()
    cust_name = first_name + ' ' + last_name
    items_text = ''
    digital_format = 'mp3'
    cds = 0
    for item in order['line_items']:
        if 'lp' in item['name'].lower() or '45' in item['name'].lower() and 'lp' not in items_text and '45' not in items_text:
            items_text = 'record' if item['quantity'] == 1 else 'records'
        elif 'cassette' in item['name'] and 'cassette' not in items_text:
            if items_text:
                items_text += ' and '
            items_text += 'cassette' if item['quantity'] == 1 else 'cassettes'
        for meta in item['meta']:
            if meta['key'] == 'mp3-download':
                digital_format = meta['value']
        if 'cd' in item['name'].lower():
            cds += item['quantity']
    total_items = sum([item['quantity'] for item in order['line_items'] if 'cassette' in item['name'] or 'lp' in item['name'].lower() or \
        '45' in item['name']])
    plural = 'is' if total_items == 1 else 'are'
    no_return = True if 'no return' in order['shipping_methods'].lower() else False
    local_pu = True if 'local' in order['shipping_methods'].lower() else False
    if not no_return and not local_pu:
        total_cassettes = sum([item['quantity'] for item in order['line_items'] if 'cassette' in item['name']])
        total_lps = sum([item['quantity'] for item in order['line_items'] if 'lp' in item['name'].lower()])
        total_cd_copies = sum([item['quantity'] for item in order['line_items'] if 'copy' in item['name'].lower()])
        if 'priority' in order['shipping_methods'].lower():
            shipping_option = 'Priority'
        elif total_cassettes + total_cd_copies <= 4 and not total_lps:
            shipping_option = 'First Class'
        else:
            shipping_option = 'Media'
    if cds:
        cds_text = ' and CD'
        if cds > 1:
            cds_text += 's'
    else:
        cds_text = ''

    # Dropbox link
    if not dbox_client: dbox_client = dropbox.client.DropboxClient(dbox_token)
    dbox_order_path = order_id
    dbox_link = dbox_client.share(dbox_order_path, short_url=True)['url']

    # Printy stuff
    print ' - - - - - - - - - - - -'
    print 'Order #{0}'.format(order['id'])
    print 'Name: {0}'.format(cust_name)
    if order['customer']['billing_address']['email']:
        print 'Email: {0}'.format(cust_email)
    else:
        print '--> Error! No email found for {0}.'.format(cust_name)
    print 'Items:'
    for item in order['line_items']:
        print ' - {0} {1}'.format(item['quantity'], item['name'])
        for meta in item['meta']:
            print 'meta:', meta
    print 'Shipping:', order['shipping_methods']

    if not digital_format:
        print 'No digital items found for order #{0}.'.format(order_id)
        return

    # Build email text
    emailtext = 'Hi {0},\n\n'.format(first_name)
    emailtext += 'Your {0} order #{1} is complete and ready for download with the following link.'.format(digital_format, order_id)
    if local_pu:
        emailtext += ' Your {0} {1} ready for pickup from our 1702 Latona St office anytime Mon-Fri, 9am - 5pm.\n\n'.format(items_text, plural)
    elif no_return:
        emailtext += ' We\'ll safely dispose of your {0} after 30 days, or after you\'re satisfied with your order.\n\n'.format(items_text)
    else:
        emailtext += ' We\'ll return your {0}{1} via USPS {2} Mail, and email you a USPS Tracking number.\n\n'.format(items_text,
            cds_text, shipping_option)
    emailtext += 'Download link: {0}\n\n'.format(dbox_link)
    emailtext += 'If you have any questions, feel free to reply to this email or call us at (844) AMERYN-1.'
    emailtext += ' Thanks for choosing Ameryn Media, and have a great day!\n\n'

    # Prepare actual message
    message = 'From: Ameryn Media <*****@*****.**>\n'
    message += 'To: {0} <{1}>\n'.format(cust_name, cust_email)
    message += 'Subject: Ameryn Media - Your {0} download is ready!\n\n'.format(digital_format)
    message += emailtext

    print ' - - - - - - - - - - - -'
    print message
    print ' - - - - - - - - - - - -'
    '''
    # Send the mail
    if smtp_server:
        smtp_server.sendmail('*****@*****.**', [cust_email, '*****@*****.**'], message)
    else:
        smtp_server = smtplib.SMTP('smtp-relay.gmail.com', 587)
        smtp_server.starttls()
        smtp_server.login('*****@*****.**', 'calselptbnympllf')
        smtp_server.sendmail('*****@*****.**', [cust_email, '*****@*****.**'], message)

    # Mark no-return, local orders as Complete/Ready in WC
    if no_return:
        wc_client.update_order(order_id, '{"order": {"status": "completed"}}')
        return order_id
    elif local_pu:        
        wc_client.update_order(order_id, '{"order": {"status": "pending-pickup"}}')
    '''
    return None
コード例 #4
0
ファイル: dbox.py プロジェクト: broxeph/ameryn
def send_dbox_email(order_id, wc_client=None, dbox_client=None, smtp_server=None):
    # Check if Dropbox folder exists
    dbox_order_path = path.join(dbox_path, order_id)
    if not path.isdir(dbox_order_path):
        print "No Dropbox folder found for order #{0} at {1}.".format(order_id, dbox_order_path)
        return

    if not wc_client:
        wc_client = WooCommerceClient(wc_ck, wc_cs, base_url, oauth_enabled=False)
    order = wc_client.get_order(order_id)["order"]

    # Get variables
    cust_email = order["customer"]["billing_address"]["email"]
    first_name = order["billing_address"]["first_name"].capitalize()
    last_name = order["billing_address"]["last_name"].capitalize()
    cust_name = first_name + " " + last_name
    items_text = ""
    digital_format = "mp3"
    cds = 0
    for item in order["line_items"]:
        if (
            "lp" in item["name"].lower()
            or "45" in item["name"].lower()
            and "lp" not in items_text
            and "45" not in items_text
        ):
            items_text = "record" if item["quantity"] == 1 else "records"
        elif "cassette" in item["name"] and "cassette" not in items_text:
            if items_text:
                items_text += " and "
            items_text += "cassette" if item["quantity"] == 1 else "cassettes"
        for meta in item["meta"]:
            if meta["key"] == "mp3-download":
                digital_format = meta["value"]
        if "cd" in item["name"].lower():
            cds += item["quantity"]
    total_items = sum(
        [
            item["quantity"]
            for item in order["line_items"]
            if "cassette" in item["name"] or "lp" in item["name"].lower() or "45" in item["name"]
        ]
    )
    plural = "is" if total_items == 1 else "are"
    no_return = True if "no return" in order["shipping_methods"].lower() else False
    local_pu = True if "local" in order["shipping_methods"].lower() else False
    if not no_return and not local_pu:
        total_cassettes = sum([item["quantity"] for item in order["line_items"] if "cassette" in item["name"]])
        total_lps = sum([item["quantity"] for item in order["line_items"] if "lp" in item["name"].lower()])
        total_cd_copies = sum([item["quantity"] for item in order["line_items"] if "copy" in item["name"].lower()])
        if "priority" in order["shipping_methods"].lower():
            shipping_option = "Priority"
        elif total_cassettes + total_cd_copies <= 4 and not total_lps:
            shipping_option = "First Class"
        else:
            shipping_option = "Media"
    if cds:
        cds_text = " and CD"
        if cds > 1:
            cds_text += "s"
    else:
        cds_text = ""

    # Dropbox link
    if not dbox_client:
        dbox_client = dropbox.client.DropboxClient(dbox_token)
    dbox_order_path = order_id
    dbox_link = dbox_client.share(dbox_order_path, short_url=True)["url"]

    # Printy stuff
    print " - - - - - - - - - - - -"
    print "Order #{0}".format(order["id"])
    print "Name: {0}".format(cust_name)
    if order["customer"]["billing_address"]["email"]:
        print "Email: {0}".format(cust_email)
    else:
        print "--> Error! No email found for {0}.".format(cust_name)
    print "Items:"
    for item in order["line_items"]:
        print " - {0} {1}".format(item["quantity"], item["name"])
    print "Shipping:", order["shipping_methods"]

    if not digital_format:
        print "No digital items found for order #{0}.".format(order_id)
        return

    # Build email text
    emailtext = "Hi {0},\n\n".format(first_name)
    emailtext += "Your {0} order #{1} is complete and ready for download with the following link.".format(
        digital_format, order_id
    )
    if local_pu:
        emailtext += " Your {0} {1} ready for pickup from our 1702 Latona St office anytime Mon-Fri, 9am - 5pm.\n\n".format(
            items_text, plural
        )
    elif no_return:
        emailtext += " We'll safely dispose of your {0} after 30 days, or after you're satisfied with your order.\n\n".format(
            items_text
        )
    else:
        emailtext += " We'll return your {0}{1} via USPS {2} Mail, and email you a USPS Tracking number.\n\n".format(
            items_text, cds_text, shipping_option
        )
    emailtext += "Download link: {0}\n\n".format(dbox_link)
    emailtext += "If you have any questions, feel free to reply to this email or call us at (844) AMERYN-1."
    emailtext += " Thanks for choosing Ameryn Media, and have a great day!\n\n"

    # Prepare actual message
    message = "From: Ameryn Media <*****@*****.**>\n"
    message += "To: {0} <{1}>\n".format(cust_name, cust_email)
    message += "Subject: Ameryn Media - Your {0} download is ready!\n\n".format(digital_format)
    message += emailtext

    # print ' - - - - - - - - - - - -'
    # print message
    # print ' - - - - - - - - - - - -'

    # Send the mail
    if smtp_server:
        smtp_server.sendmail("*****@*****.**", [cust_email, "*****@*****.**"], message)
    else:
        smtp_server = smtplib.SMTP("smtp-relay.gmail.com", 587)
        smtp_server.starttls()
        smtp_server.login("*****@*****.**", "calselptbnympllf")
        smtp_server.sendmail("*****@*****.**", [cust_email, "*****@*****.**"], message)

    # Mark no-return, local orders as Complete/Ready in WC
    if no_return:
        wc_client.update_order(order_id, '{"order": {"status": "completed"}}')
        return order_id
    elif local_pu:
        wc_client.update_order(order_id, '{"order": {"status": "pending-pickup"}}')
    return None
コード例 #5
0
ファイル: test.py プロジェクト: Buyasta/WooCommerceClient
import sys
sys.path.append('..')
from WooCommerceClient import WooCommerceClient
import pprint

wc_client = WooCommerceClient('ck_5e5692af317c09ca4581be6bc5596714', 'cs_3115cf0868e4ae29117257e13cec6248', 'http://wpdev/')
pprint.pprint(wc_client.get_products())
コード例 #6
0
ファイル: wc_get_test.py プロジェクト: broxeph/ameryn
from WooCommerceClient import WooCommerceClient
import pprint
import sys

ck = 'ck_bc1ac58b5dc9099c8df1789f811afa2d'
cs = 'cs_7199c23290742677aed84294861ed73b'
base_url = 'https://www.ameryn.com/'
wc_client = WooCommerceClient(ck, cs, base_url, oauth_enabled=False)
requested_order_id = 3050
data = '{"order": {"status": "completed"}}'

#pprint.pprint(wc_client.get_order(requested_order_id))
#wc_client.update_order(requested_order_id, data)
order = wc_client.get_order(requested_order_id)['order']

# Get variables
print 'cust_email:', order['customer']['billing_address']['email']
print 'status:', order['status']
print 'notes:', order['note']

orders = wc_client.get_orders()['orders']
print 'orders:'
#pprint.pprint(orders[0])
for order in orders:
    print '{0} - {1}'.format(order['id'], order['status'])
コード例 #7
0
ファイル: wc-post-test.py プロジェクト: broxeph/ameryn
from WooCommerceClient import WooCommerceClient
import pprint
import sys
import dropbox

ck = 'ck_bc1ac58b5dc9099c8df1789f811afa2d'
cs = 'cs_7199c23290742677aed84294861ed73b'
base_url = 'https://www.ameryn.com/'
wc_client = WooCommerceClient(ck, cs, base_url, oauth_enabled=False)
requested_order_id = 2572
dbox_token = 'asEt1sv4B_0AAAAAAAAFC7AWI6KFNqvxFx2o73NUOLERBg8VxVfsRGSHzqfOqCtL'
data = '{"order": {"status": "completed"}}'

#pprint.pprint(wc_client.get_order(requested_order_id))
wc_client.update_order(requested_order_id, data)
order = wc_client.get_order(requested_order_id)['order']

# Get variables
print 'cust_email:', order['customer']['billing_address']['email']
print 'status:', order['status']
print 'notes:', wc_client.get_order_notes(requested_order_id)
コード例 #8
0
ファイル: test.py プロジェクト: paulrsilva/WooCommerceClient
import sys
sys.path.append('..')
from WooCommerceClient import WooCommerceClient
import pprint

wc_client = WooCommerceClient('ck_5e5692af317c09ca4581be6bc5596714',
                              'cs_3115cf0868e4ae29117257e13cec6248',
                              'http://wpdev/')
pprint.pprint(wc_client.get_products())