Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Works with python3 #6

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@
build
dist
html
pyShipping.egg-info
*.egg-info
*.bak
9 changes: 8 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
pyShipping provides connections to interface with shipping companies and to transport shipping related information.
I take no credit for the excellent pyShipping (https://github.com/hudora/pyShipping) module. All I've done is fork their repo and make it python3 compatible. For the record, I submitted a pull request to the original maintainers almost 6 weeks ago (at the time of writing) but the project appears to be dormant and I needed this available via pip install today.

Install via...
pip install pyShipping-python3

---

pyShipping provides connections to interface with shipping companies and to transport shipping related information.

* package - shipping/cargo related calculations based on a unit of shipping (box, crate, package), includes
a bin packing implementation in pure Python
Expand Down
10 changes: 5 additions & 5 deletions pyshipping/binpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"""


import binpack_simple
import pyshipping.binpack_simple

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have this error when calling the funtion binpack below this line

NameError: name 'binpack_simple' is not defined

In my opinion, we should do something like this:
import pyshipping.binpack_simple as binpack_simple



def binpack(packages, bin=None, iterlimit=5000):
Expand All @@ -32,16 +32,16 @@ def test(func):
continue
bins, rest = func(packages)
if rest:
print "invalid data", rest, line
print("invalid data", rest, line)
else:
vorher += len(packages)
nachher += len(bins)
print time.time() - start,
print vorher, nachher, float(nachher) / vorher * 100
print(time.time() - start)
print(vorher, nachher, float(nachher) / vorher * 100)


if __name__ == '__main__':
print "py",
print("py")
test(binpack)


Expand Down
12 changes: 6 additions & 6 deletions pyshipping/binpack_simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def packlayer(bin, packages):


def packbin(bin, packages):
packages.sort()
packages.sort(key=lambda x: x.volume)
layers = []
contentheigth = 0
contentx = 0
Expand All @@ -121,7 +121,7 @@ def packbin(bin, packages):

def packit(bin, originalpackages):
packedbins = []
packages = sorted(originalpackages)
packages = sorted(originalpackages, key=lambda x: x.volume)
while packages:
packagesinbin, (binx, biny, binz), rest = packbin(bin, packages)
if not packagesinbin:
Expand All @@ -139,7 +139,7 @@ def packit(bin, originalpackages):
def product(*args, **kwds):
# product('ABCD', 'xy') --> Ax Ay Bx By Cx Cy Dx Dy
# product(range(2), repeat=3) --> 000 001 010 011 100 101 110 111
pools = map(tuple, args) * kwds.get('repeat', 1)
pools = list(map(tuple, args)) * kwds.get('repeat', 1)
result = [[]]
for pool in pools:
result = [x + [y] for x in result for y in pool]
Expand Down Expand Up @@ -222,12 +222,12 @@ def test():
continue
bins, rest = binpack(packages)
if rest:
print "invalid data", rest, line
print("invalid data", rest, line)
else:
vorher += len(packages)
nachher += len(bins)
print time.time() - start,
print vorher, nachher, float(nachher) / vorher * 100
print(time.time() - start)
print(vorher, nachher, float(nachher) / vorher * 100)


if __name__ == '__main__':
Expand Down
78 changes: 39 additions & 39 deletions pyshipping/fortras/entl.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class Entladebericht(object):
# Gitterbox-Paletten-Entladung Empfangspartner kann 3/0 115 - 117
# Verkehrsart** kann 1 118 - 118
# Frei 9 119 - 127
# Releasestand ���5’ muss 1 128 - 128
# Releasestand ���5’ muss 1 128 - 128

n_record_re = (r'N(?P<borderonr>[0-9 ]{18})(?P<position>[0-9 ]{3})(?P<sendungsnrversender>[0-9 ]{16})'
+ r'(?P<sendungsnrempfaenger>[0-9 ]{16})(?P<differenzschluessel1>..)'
Expand All @@ -51,11 +51,11 @@ class Entladebericht(object):
# Laufende Bordero-Position Versandpartner muss 3/0 020 - 022
# Sendungs-Nr. Versandpartner muss 16 023 - 038
# Sendungs-Nr. Empfangspartner muss 16 039 - 054
# Differenzartschlu�ssel 1* muss 2 055 - 056
# Differenzartschlu�ssel 1* muss 2 055 - 056
# Differenzanzahl 1 kann 4/0 057 - 060
# Verpackungsart 1** kann 2 061 - 062
# Text/Hinweis 1 kann 29 063 - 091
# Differenzartschlu�ssel 2* kann 2 092 - 093
# Differenzartschlu�ssel 2* kann 2 092 - 093
# Differenzanzahl 2 kann 4/0 094 - 097
# Verpackungsart 2** kann 2 098 - 099
# Text/Hinweis 2 kann 29 100 - 128
Expand All @@ -66,60 +66,60 @@ class Entladebericht(object):
+ r'(?P<date>[0-9 ]{8})(?P<time>[0-9 ]{4})'
+ r'(?P<benutzer>.{10})(?P<terminal>.{4})')
v_record_re = re.compile(v_record_re)
# Lo�st 'N'-Satz ab bei Einsatz von Barcode
# Lo�st 'N'-Satz ab bei Einsatz von Barcode
# Satzart ‘V’ muss 1 001 - 001
# Bordero-Nr. Versandpartner muss 18 002 - 019
# Sendungs-Nr. Versandpartner muss 16 020 - 035
# Barcode-Qualifier * kann 3 036 - 038
# Barcode-Nr. muss 35 039 - 073
# Fehler-/Hinweiscode 1 ** muss 3 074 - 076
# Frei wa�hlbarer Text/Hinweis kann 24 077 - 100
# Frei wa�hlbarer Text/Hinweis kann 24 077 - 100
# Ereignisdatum (TTMMJJJJ) muss 8 101 - 108
# Ereignisuhrzeit (HHMMSS) muss 6 109 - 114
# Benutzer-ID kann 10 115 - 124
# Scanner/Terminal-ID kann 4 125 - 128
# Fehler-/Hinweiscode:
statustexte = {
0: 'Packst�ck',
2: 'Packst�ck eingedr�ckt',
3: 'Packst�ck aufgerissen, Ware greifbar',
4: 'Packst�ck nass',
5: 'Packst�ckinhalt l�uft aus',
9: 'Packst�ck besch�digt',
0: 'Packst�ck',
2: 'Packst�ck eingedr�ckt',
3: 'Packst�ck aufgerissen, Ware greifbar',
4: 'Packst�ck nass',
5: 'Packst�ckinhalt l�uft aus',
9: 'Packst�ck besch�digt',
10: 'Euro-Palette',
11: 'Euro-Palette, Ware besch�digt',
12: 'Euro-Palette besch�digt',
13: 'Euro-Palette und Ware besch�digt',
14: 'Euro-Palette verschwei�t/gewickelt',
11: 'Euro-Palette, Ware besch�digt',
12: 'Euro-Palette besch�digt',
13: 'Euro-Palette und Ware besch�digt',
14: 'Euro-Palette verschwei�t/gewickelt',
15: 'Euro-Palette, Folie ein-/aufgerissen, Ware greifbar',
19: 'Euro-Palette und/oder Ware mit Besch�digung',
19: 'Euro-Palette und/oder Ware mit Besch�digung',
20: 'Gitterbox',
21: 'Gitterbox, Ware besch�digt',
22: 'Gitterbox besch�digt',
23: 'Gitterbox und Ware besch�digt',
29: 'Gitterbox und/oder Ware mit Besch�digung',
21: 'Gitterbox, Ware besch�digt',
22: 'Gitterbox besch�digt',
23: 'Gitterbox und Ware besch�digt',
29: 'Gitterbox und/oder Ware mit Besch�digung',
30: 'Halbpalette',
31: 'Halbpalette, Ware besch�digt',
32: 'Halbpalette besch�digt',
33: 'Halbpalette und Ware besch�digt',
34: 'Halbpalette verschwei�t/gewickelt',
31: 'Halbpalette, Ware besch�digt',
32: 'Halbpalette besch�digt',
33: 'Halbpalette und Ware besch�digt',
34: 'Halbpalette verschwei�t/gewickelt',
35: 'Halbpalette, Folie ein-/aufgerissen, Ware greifbar',
39: 'Halbpalette und/oder Ware mit Besch�digung',
39: 'Halbpalette und/oder Ware mit Besch�digung',
40: 'Einwegpalette',
41: 'Einwegpalette, Ware besch�digt',
42: 'Einwegpalette besch�digt',
43: 'Einwegpalette und Ware besch�digt',
44: 'Einwegpalette verschwei�t/gewickelt',
41: 'Einwegpalette, Ware besch�digt',
42: 'Einwegpalette besch�digt',
43: 'Einwegpalette und Ware besch�digt',
44: 'Einwegpalette verschwei�t/gewickelt',
45: 'Einwegpalette, Folie ein-/aufgerissen, Ware greifbar',
49: 'Einwegpalette und/oder Ware mit Besch�digung.',
50: 'Packst�ck fehlt bei Entladung', # (Wird durch Entladebericht beim EP erzeugt)
49: 'Einwegpalette und/oder Ware mit Besch�digung.',
50: 'Packst�ck fehlt bei Entladung', # (Wird durch Entladebericht beim EP erzeugt)
51: 'Backbox SK1*',
52: 'Backbox SK2*',
53: 'Backbox SK3*',
54: 'Backbox SK4*',
62: 'HUB/Konsolidierungspunkt - Packst�ck handverteilt',
63: 'HUB/Konsolidierungspunkt - Palette mit �berma�',
64: 'HUB/Konsolidierungspunkt - Packstu�ckroutung nicht lesbar (Nachbearbeitung)',
62: 'HUB/Konsolidierungspunkt - Packst�ck handverteilt',
63: 'HUB/Konsolidierungspunkt - Palette mit �berma�',
64: 'HUB/Konsolidierungspunkt - Packstu�ckroutung nicht lesbar (Nachbearbeitung)',
65: 'HUB/Konsolidierungspunkt - Versender Direktanlieferung - Aufkleber erstellt',
66: 'HUB/Konsolidierungspunkt - Dienstleistung - Routung durch HUB / Konsolidierungspunkt',
67: 'HUB/Konsolidierungspunkt - Dienstleistung - Vereinbarte Nachbearbeitung',
Expand All @@ -131,7 +131,7 @@ class Entladebericht(object):
95: 'PLZ-Fehler*',
96: 'Platzmangel',
97: 'Zeitmangel',
98: 'R�ckscannung - Packstu�ck wieder entladen',
98: 'R�ckscannung - Packstu�ck wieder entladen',
99: 'Korrekturscannung',
}

Expand Down Expand Up @@ -188,18 +188,18 @@ def parse(self, data):
if line[0] == 'M':
match = re.search(Entladebericht.m_record_re, line)
if not match:
print 'no match', repr(line)
print('no match', repr(line))
# the content of M records are ignored
elif line[0] == 'N':
match = re.search(Entladebericht.n_record_re, line)
if not match:
print 'no match', repr(line)
print('no match', repr(line))
# the content of N records are ignored
elif line[0] == 'V':
match = re.search(Entladebericht.v_record_re, line)
newdict = {}
if not match:
print 'no match', repr(line)
('no match', repr(line))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why did you delete this print?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well spotted, I think that one was deleted in eror.

for key, value in match.groupdict().items():
newdict[key] = value.strip()
newdict['timestamp'] = datetime.datetime(int(newdict['date'][4:]), int(newdict['date'][2:4]),
Expand All @@ -211,4 +211,4 @@ def parse(self, data):
elif line[0] == 'W':
pass # we happyly ignore W records
else:
print "unknown %r" % line
print("unknown %r" % line)
2 changes: 1 addition & 1 deletion pyshipping/fortras/fortras_stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ def parse(self, data):
match = re.search(Statusmeldung.q_record_re, line)
newdict = {}
if not match:
print 'no match', repr(line)
print('no match', repr(line))
for key, value in match.groupdict().items():
newdict[key] = value.strip()
try:
Expand Down
10 changes: 5 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
from distutils.extension import Extension
import codecs

setup(name='pyShipping',
maintainer='Maximillian Dornseif',
maintainer_email='[email protected]',
url="https://github.com/hudora/pyShipping/",
version='1.9',
setup(name='pyShipping-python3',
maintainer='Jon Combe via Maximillian Dornseif',
maintainer_email='[email protected]',
url="https://github.com/joncombe/pyShipping-python3",
version='0.0.1',
description='pyShipping - Shipping related Toolkit',
long_description=codecs.open('README.rst', "r", "utf-8").read(),
classifiers=['License :: OSI Approved :: BSD License',
Expand Down