olivier.massot 8 лет назад
Сommit
cff94d19f5
4 измененных файлов с 62 добавлено и 0 удалено
  1. 5 0
      .gitignore
  2. 0 0
      core/__init__.py
  3. 41 0
      core/wsparser.py
  4. 16 0
      factures.py

+ 5 - 0
.gitignore

@@ -0,0 +1,5 @@
+*.pyc
+.project
+.pydevproject
+Output/
+htmlcov/

+ 0 - 0
core/__init__.py


+ 41 - 0
core/wsparser.py

@@ -0,0 +1,41 @@
+
+import urllib.request
+
+from lxml import etree  # @UnresolvedImport
+
+
+class WSParser():
+    """ Parser for a web service """
+    def __init__(self, url):
+        self._url = url
+        self._data = None
+
+    @property
+    def url(self):
+        return self._url
+
+    def parse(self):
+        strxml = urllib.request.urlopen(self._url).read()
+        self._data = etree.fromstring(strxml)
+
+    def __iter__(self):
+        if self._data is None:
+            self.parse()
+        return (node.attrib for node in self._data)
+
+# OU
+#
+# from _io import BytesIO
+# URL = 'http://localhost:2890/public/WsPDE.asmx/GetPDETitres'
+#
+# data = urllib.request.urlopen(URL).read()
+#
+# for _, element in etree.iterparse(BytesIO(data)):
+#     print(element.attrib)
+
+if __name__ == "__main__":
+
+    ws_url = 'http://localhost:2890/public/WsPDE.asmx/GetPDETitres'
+    for elt in WSParser(ws_url):
+        print(elt)
+

+ 16 - 0
factures.py

@@ -0,0 +1,16 @@
+'''
+Created on 27 juin 2017
+
+@author: olivier.massot
+'''
+from _io import BytesIO
+import urllib.request
+from lxml import etree  # @UnresolvedImport
+
+
+URL = 'http://localhost:2890/public/WsPDE.asmx/GetPDETitres'
+
+data = urllib.request.urlopen(URL).read()
+
+for _, element in etree.iterparse(BytesIO(data)):
+    print(element.attrib)