Пример #1
0
def quick_import(file_name='all.csv'):
    csv_file = open_csv(file_name)
    for i, line in enumerate(csv_file):
        if not i:
            continue  # skip header
        json_data = get_dict(line, i)
        a = json.dumps([json_data])
        print "%s. %s | %s : %s" % (
            i, json_data['id_1c'], json_data['name'], json_data['leftovers']
        )
        h = httplib2.Http()
        resp, content = h.request(
            URL,
            'POST',
            a,
            headers={'Content-Type': 'application/json'})
        print resp
    print "========================================================"
Пример #2
0
def cleanup(file_name='all.csv'):
    csv_file = open_csv(file_name)
    local_1c_ids = []
    for line in csv_file:
        json_data = get_dict(line)
        if json_data['id_1c']:
            local_1c_ids.append(json_data['id_1c'])
    remote_1c_ids = get_remote_1c_ids()
    for id in remote_1c_ids:
        if id not in local_1c_ids:
            print 'Prepare to delete %s' % id
            json_data = {
                'status': 90,
                'id_1c': id,
                'in_trash': True
            }
            a = json.dumps([json_data])
            h = httplib2.Http()
            resp, content = h.request(
                URL,
                'POST',
                a,
                headers={'Content-Type': 'application/json'})
            print resp