Skip to content

Commit

Permalink
add basic ability to print png out
Browse files Browse the repository at this point in the history
  • Loading branch information
kronicka committed Jan 20, 2019
1 parent 900eca3 commit ec0f94b
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion app.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,5 +44,5 @@ def calculate_weeks(sex: bool, country_index: int, dob: Tuple[int, int, int]) ->
if __name__ == '__main__':
inputs = input_all()
weeks = calculate_weeks(*inputs)
generate_calendar_svg(weeks)
generate_calendar_svg(weeks, 'png')

3 changes: 2 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ Pillow>=5.3.0
python-dateutil
pycountry>=18.12.8
requests
svgwrite
svgwrite
wand
13 changes: 11 additions & 2 deletions utils/calendar.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import svgwrite
from wand.image import Image
from utils.constants import CAL_SIZE, CSS_STYLES


def generate_calendar_svg(units: int, unit_type: str = 'weeks'):
def generate_calendar_svg(units: int, file_format: str, unit_type: str = 'weeks'):
"""
Generate an svg calendar based on the number of weeks
"""
Expand Down Expand Up @@ -43,6 +44,14 @@ def group(classname):
dwg.add(dwg.text(units_label, insert=(360, 580), font_size='5px', fill='grey'))
dwg.save()

svg_file = open('calendar.svg', mode='wb')
with Image(blob=svg_file.read(), format="svg") as image:
png_image = image.make_blob("png")
svg_file.close()

with open('calendar.png', mode='wb') as png_out:
png_out.write(png_image)


if __name__ == '__main__':
generate_calendar_svg(100)
generate_calendar_svg(100, 'png')

0 comments on commit ec0f94b

Please sign in to comment.