Skip to content

Commit

Permalink
Ready for a new release
Browse files Browse the repository at this point in the history
Added a feature that reads the given gcode file and returns the duration of the print and the material used in metric units.

Fixed a bug which makes the program execute the md5 function before creating the byte version of the original gcode.
  • Loading branch information
egeakman committed Mar 30, 2022
1 parent 947da8a commit d854147
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 22 deletions.
54 changes: 38 additions & 16 deletions gcode2zaxe/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import zipfile
import hashlib
import tempfile
import datetime
from argparse import ArgumentParser

TMP = tempfile.gettempdir()
Expand Down Expand Up @@ -63,29 +64,50 @@ def md5():
return hash_md5.hexdigest()


def read_gcode():
gcode_info = {}
with open(args.gcode, "r") as f:
for line in f.readlines():
if line.startswith(";TIME:"):
time = int(line.split(";TIME:")[1].strip())
gcode_info["time"] = str(datetime.timedelta(seconds=time))

with open(args.gcode, "r") as f:
for line in f.readlines():
if line.startswith(";Filament used:"):
filament_used = round(
float(line.split(";Filament used:")[1].strip().replace("m", "")), 2
)
gcode_info["filament_used"] = f"{str(filament_used)}m"

return gcode_info


def make_info():
return {
"material": args.filament,
"nozzle_diameter": args.nozzle_diameter,
"filament_used": read_gcode()["filament_used"],
"model": args.model,
"checksum": md5(),
"name": args.name,
"duration": read_gcode()["time"],
"extruder_temperature": 220,
"bed_temperature": 60,
"version": "1.0.4",
}


def main():
with open(os.path.join(TMP, "info.json"), "w") as f:
f.write(json.dumps(info))

encoded = convert_to_bytes(args.gcode)

with open(os.path.join(TMP, "o.gcode"), "wb") as f:
f.write(encoded)

with open(os.path.join(TMP, "info.json"), "w") as f:
f.write(json.dumps(make_info()))

open(os.path.join(TMP, "snapshot.png"), "w").close()

create_zaxe()


info = {
"material": args.filament,
"nozzle_diameter": args.nozzle_diameter,
"filament_used": 1000.0,
"model": args.model,
"checksum": md5(),
"name": args.name,
"duration": "00:20:00",
"extruder_temperature": 220,
"bed_temperature": 60,
"version": "1.0.4",
}
11 changes: 5 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
import contextlib
import json
import urllib.request
from setuptools import setup, find_packages


def latest_version(package_name):
url = f"https://pypi.python.org/pypi/{package_name}/json"
try:
with contextlib.suppress(Exception):
response = urllib.request.urlopen(urllib.request.Request(url), timeout=1)
data = json.load(response)
versions = data["releases"].keys()
versions = sorted(versions)
return ">={}".format(versions[-1])
except Exception:
pass
return f">={versions[-1]}"
return ""


Expand All @@ -27,9 +26,9 @@ def latest_version(package_name):
description="Gcode to Zaxe Converter | executable: g2z",
long_description=long_description,
long_description_content_type="text/markdown",
version="2022.3.15-2",
version="2022.3.30",
license="AGPLv3",
download_url="https://github.com/egeakman/gcode2zaxe/archive/2022.3.15-2.tar.gz",
download_url="https://github.com/egeakman/gcode2zaxe/archive/2022.3.30.tar.gz",
packages=find_packages(where=".", exclude=["tests"]),
python_requires=">=3.5",
entry_points={
Expand Down

0 comments on commit d854147

Please sign in to comment.