Пример #1
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from SugarCRMAPI import SugarCRMAPI
import os
from os.path import basename
import csv

host = ""
user_name = ""
password = ""
clientId = ""
clientSecret = ""
directory = ""
api = SugarCRMAPI(host, clientId, clientSecret)
result = api.oauth2_token(user_name, password)
# Validar access_token
uploaded = False
with open('result.csv', 'wb') as csvfile:
    spamwriter = csv.writer(csvfile,
                            delimiter=',',
                            quotechar='"',
                            quoting=csv.QUOTE_ALL,
                            skipinitialspace=True)
    for dirname, dirnames, filenames in os.walk(directory):
        if uploaded:
            break
        for filename in filenames:
            if uploaded:
                break
            path = os.path.join(dirname, filename)
            filename, file_extension = os.path.splitext(path)
from SugarCRMAPI import SugarCRMAPI
import os
from os.path import basename
import csv
import mimetypes
host = ""
user_name = ""
password = ""
clientId = ""
clientSecret = ""
directory = ""
field_name = ""
csv_import = ""
module_name = ""

api = SugarCRMAPI(host, clientId, clientSecret)
result = api.oauth2_token(user_name, password)

with open(csv_import, 'rb') as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
        url = "{module_name}/{1}/file/{3}?format=json&delete_if_fails=true&oauth_token={2}".format(
            module_name=module_name,
            row['producttemplate_id'],
            api.access_token,
        )
        path = "{1}/{0}".format(row['path'], directory)
        file_content = open(path, 'rb')
        filename, file_extension = os.path.splitext(path)
        content_type = mimetypes.types_map[file_extension]
        result = api.upload(url, file_content, content_type, field_name)
from SugarCRMAPI import SugarCRMAPI
import os
from os.path import basename
import csv
import mimetypes
host = ""
user_name = ""
password = ""
clientId = ""
clientSecret = ""
directory = ""
field_name = ""
csv_import = ""
module_name = ""

api = SugarCRMAPI(host, clientId, clientSecret)
result = api.oauth2_token(user_name, password)

with open(csv_import, 'rb') as csvfile:
	reader = csv.DictReader(csvfile)
	for row in reader:
		url = "{module_name}/{producttemplate_id}/file/{field_name}?format=json&delete_if_fails=false&oauth_token={access_token}".format(module_name=module_name,producttemplate_id=row['producttemplate_id'], access_token=api.access_token,field_name=field_name )
		path = "{1}/{0}".format(row['path'],directory)
		file_content = open(path,'rb')
		filename, file_extension = os.path.splitext(path)
		content_type = mimetypes.types_map[file_extension.lower()]
		result = api.upload(url, file_content, content_type, field_name)
		print "{0}#ProductTemplates/{1}".format(host,row['producttemplate_id'])

		
Пример #4
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from SugarCRMAPI import SugarCRMAPI
import os
from os.path import basename
import csv
host = ""
user_name = ""
password = ""
clientId = ""
clientSecret = ""

api = SugarCRMAPI(host, clientId, clientSecret)
result = api.oauth2_token(user_name, password)

with open('products.csv', 'rb') as csvfile:
    reader = csv.DictReader(csvfile)
    for row in reader:
        print row['producttemplate_id']
        result = api.create_link("ProductTemplates", row['producttemplate_id'],
                                 "producttemplates_documents_1",
                                 row['document_id'])
        print result
Пример #5
0
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from SugarCRMAPI import SugarCRMAPI
import os
from os.path import basename
import csv
host = ""
user_name = ""
password = ""
clientId = ""
clientSecret = ""
directory = ""
api = SugarCRMAPI(host, clientId, clientSecret)
result = api.oauth2_token(user_name, password)
# Validar access_token
uploaded = False
with open('result.csv', 'wb') as csvfile:
  spamwriter = csv.writer(csvfile, delimiter=',',quotechar='"', quoting=csv.QUOTE_ALL, skipinitialspace=True)
  for dirname, dirnames, filenames in os.walk(directory):
    if uploaded :
      break
    for filename in filenames:
      if uploaded :
        break
      path = os.path.join(dirname, filename)
      filename, file_extension = os.path.splitext(path)
      if file_extension == ".pdf":
        data = {
            "name": basename(filename),
            }
        result = api.save('Documents',data)