Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion odata1c/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
from odata1c import service
from .odata1c import service
1 change: 1 addition & 0 deletions odata1c/__init__.py.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from odata1c import service
12 changes: 6 additions & 6 deletions odata1c/odata1c.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# -*- coding: utf-8 -*-

import urllib2
import urllib.request, urllib.error, urllib.parse
import feedparser
import requests
import xml.etree.ElementTree as etree

from odata1cparser import Odata1cObj
from .odata1cparser import Odata1cObj



Expand Down Expand Up @@ -33,12 +33,12 @@ def __init__(self, url, login, password):


def read (self, collection='', entry=''):
if collection not in self.workspace.keys():
print '[ERROR] Workspace has no ', collection
if collection not in list(self.workspace.keys()):
print(('[ERROR] Workspace has no ', collection))
return

if entry not in self.workspace[collection]:
print '[ERROR] %s has no '%(collection,), entry
print(('[ERROR] %s has no '%(collection,), entry))
return

query_url = self.url + collection+'_'+ entry
Expand Down Expand Up @@ -81,7 +81,7 @@ def __getattribute__(self, name):
ret_res = super(service, self).__getattribute__(name)
except AttributeError:
workspace = super(service, self).__getattribute__('workspace')
if name in workspace.keys():
if name in list(workspace.keys()):
db1c = Odata1cObj( self, name)
#db1c.append_items(workspace[name])
#db1c.load()
Expand Down
110 changes: 110 additions & 0 deletions odata1c/odata1c.py.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
# -*- coding: utf-8 -*-

import urllib.request, urllib.error, urllib.parse
import feedparser
import requests
import xml.etree.ElementTree as etree

from .odata1cparser import Odata1cObj




class service(object):

def __init__(self, url, login, password):
self.url = url
self.login = login
self.password = password
self.workspace = self.get_workspace()

# for key in self.workspace.keys():
# setattr(self, key, Odata1cObj( self, key) )
# statr = getattr(self, key)
# statr.append_items(self.workspace[key])


#Четение всех таблиц из 1C Workspace только для таких как Catalog и Document
# for item in self.workspace[name]:
# print item
# setattr(self, item, Odata1cObj( self, name) )




def read (self, collection='', entry=''):
if collection not in list(self.workspace.keys()):
print('[ERROR] Workspace has no ', collection)
return

if entry not in self.workspace[collection]:
print('[ERROR] %s has no '%(collection,), entry)
return

query_url = self.url + collection+'_'+ entry
req = requests.get(query_url, auth=(self.login, self.password))
root = etree.fromstring(req.text.encode('utf-8'))
return root




def get_workspace(self):
catalog_dict = list()
document_dict = list()

#if element.find('...') is not None.

req = requests.get(self.url, auth=(self.login, self.password))
root = etree.fromstring(req.text.encode('utf-8'))

#print root[0][1]
#print root[0][1][0].text

collections = root[0].findall('{http://www.w3.org/2007/app}collection')

for collection in collections:
txt = collection[0].text
splitted = txt.split('_')

if 'Catalog' in splitted:
catalog_dict.append( txt.replace('Catalog_','') )
elif 'Document' in splitted:
document_dict.append( txt.replace('Document_','') )

workspace = {'Catalog' : catalog_dict, 'Document':document_dict}
return workspace

def __getattribute__(self, name):

try:
ret_res = super(service, self).__getattribute__(name)
except AttributeError:
workspace = super(service, self).__getattribute__('workspace')
if name in list(workspace.keys()):
db1c = Odata1cObj( self, name)
#db1c.append_items(workspace[name])
#db1c.load()
setattr(self, name, db1c)

#ret_res = db1c.load()
ret_res = db1c

return ret_res


#object.__getattribute__(self, 'workspace')
# if name in workspace:
# db1c = object.__getattribute__(self, name)
# print 'Downloading from 1C..'
# return db1c.load()
# else:









12 changes: 6 additions & 6 deletions odata1c/odata1cparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@ def __init__(self, service, name):

def load(self):
#http://95.79.53.147:9080/bit_nn123/odata/standard.odata/Document_Order
if self.name in self.service.workspace.keys():
print 'Downloading ',self.name, '...'
if self.name in list(self.service.workspace.keys()):
print(('Downloading ',self.name, '...'))
#self.items = self.service.get_workspace()[self.name]
for i in self.items:
print self.name, i
print((self.name, i))
root = self.service.read(self.name, i)
self.parse_xml(root,i)

Expand Down Expand Up @@ -57,13 +57,13 @@ def __str__(self):
def __getitem__(self,index):

if index in self.service.workspace[self.name]:
print self.name+'_'+index
print((self.name+'_'+index))
root = self.service.read(self.name, index)
print root.tag
print((root.tag))
self.parse_xml(root,index)
res = self.items[index]
else:
print index,' Not in ', self.name
print((index,' Not in ', self.name))
res = {}
# if index in :
# print self.name+'_'+index
Expand Down
80 changes: 80 additions & 0 deletions odata1c/odata1cparser.py.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# -*- coding: utf-8 -*-




class Obj1C(object):

def __init__(self, service, name):
self.service = service
self.name = name
self.items=dict()
#self.load()


def load(self):
#http://95.79.53.147:9080/bit_nn123/odata/standard.odata/Document_Order
if self.name in list(self.service.workspace.keys()):
print('Downloading ',self.name, '...')
#self.items = self.service.get_workspace()[self.name]
for i in self.items:
print(self.name, i)
root = self.service.read(self.name, i)
self.parse_xml(root,i)

return self.items


def parse_xml(self,root,table):
entrys = root.findall('{http://www.w3.org/2005/Atom}entry')
if len(entrys) > 0:
#print len(entrys)

self.items[table]={'entry' : { 'content' : [] } }


for entry in entrys:

contents = entry.findall('{http://www.w3.org/2005/Atom}content')
for content in contents:
properties = content.findall('{http://schemas.microsoft.com/ado/2007/08/dataservices/metadata}properties')
prop_dict = dict()
for prop in properties[0]:
key = prop.tag.split('}')[-1]
prop_dict[key]=prop.text

self.items[table]['entry']['content'].append(prop_dict)



def append_items(self, items):
for i in items:
self.items[i]=dict()

def __str__(self):
return str(self.items)

def __getitem__(self,index):

if index in self.service.workspace[self.name]:
print(self.name+'_'+index)
root = self.service.read(self.name, index)
print(root.tag)
self.parse_xml(root,index)
res = self.items[index]
else:
print(index,' Not in ', self.name)
res = {}
# if index in :
# print self.name+'_'+index
# root = self.service.read(self.name, index)
# print root.tag

return res





class Odata1cObj(Obj1C):
pass
2 changes: 1 addition & 1 deletion test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
catalogs = service.Catalog

for i in catalogs['SKUGroup']['entry']['content']:
print i
print(i)
#print service.Document['Order']


Expand Down
22 changes: 22 additions & 0 deletions test.py.bak
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from odata1c import odata1c
import xml.etree.ElementTree as etree
import requests


url = 'http://localhost/odata/standard.odata/'

service = odata1c.service(url=url, login='admin', password='')

#print service.workspace['Catalog']

catalogs = service.Catalog

for i in catalogs['SKUGroup']['entry']['content']:
print i
#print service.Document['Order']