{"id":9558,"date":"2023-04-02T04:36:31","date_gmt":"2023-04-02T04:36:31","guid":{"rendered":"https:\/\/max-drake.cc\/?p=9558"},"modified":"2023-04-02T19:49:36","modified_gmt":"2023-04-02T19:49:36","slug":"python-create-daily-planets-epheremis-email-automate","status":"publish","type":"post","link":"https:\/\/max-drake.cc\/?p=9558","title":{"rendered":"Python create Daily Planets Epheremis, Email &amp; Automate"},"content":{"rendered":"\n<p>After creating a visualisation of planets orbiting in the solar system I wanted to see if I could create a daily Epheremis of planetary bodies for my particular location with Altitude &amp; Azimuth locations at hourly intervals and then send it to myself via an email so that I could access it on my mobile phone if I was outside.<\/p>\n\n\n\n<p>The end result is not aligned quite properly on the page and the text is a bit small, but I was interested in getting the process right so that I could automate it from start to finish, and from that point I get a daily delivered email to my inbox with a pdf attachment with the epheremis information for where I live. <\/p>\n\n\n\n<figure class=\"wp-block-image size-full is-resized\"><img decoding=\"async\" data-src=\"https:\/\/max-drake.cc\/wp-content\/uploads\/2023\/04\/2023-04-02-Planets-Epheremis-for-Wellington-for-Max.pdf-Mozilla-Thunderbird2023-04-02-16_31.jpg\" alt=\"\" class=\"wp-image-9559 lazyload\" width=\"837\" height=\"585\" src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" style=\"--smush-placeholder-width: 837px; --smush-placeholder-aspect-ratio: 837\/585;\" \/><figcaption class=\"wp-element-caption\">PDF Table with Epheremis information for hourlyy intervals from a CSV output from a python script.<\/figcaption><\/figure>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Python create Daily Planets Epheremis, Email &amp; Automate\" width=\"678\" height=\"381\" data-src=\"https:\/\/www.youtube.com\/embed\/pWG7PhldcG4?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><br>In producing the Epheremis (a table showing the positions of a heavenly body on a number of dates in a regular sequence) the script produces the data in a CSV format. That format is not that useful to view on a small screen, so I wanted a different format.<br>So an extra bit of learning was to convert the CSV output into a PDF table. A PDF is better than an image as it does not pixelate when you zoom in on a part of the image, so it is useful on small screens.<br>The PyEphem library was great and produced the tables very quickly in the format that I wanted (Alt\/Az instead of RA &amp; Dec) and I checked a couple of the results with Stellarium, just to see that I was in the right ballpark.<br>So I had the content that I wanted, I just needed it in the format that I wanted and then I had to look at a delivery process, in this case via email.<br>The email process threw me a bit as I&#8217;d only used CSV attachments to emails and that automation reads the attched file before sending it, so I needed to reconfigure the email code to be able to add a PDF attachment.<br><strong><a rel=\"noreferrer noopener\" href=\"https:\/\/rhodesmill.org\/pyephem\/\" target=\"_blank\">PyEphem<\/a><\/strong> library, <strong><a rel=\"noreferrer noopener\" href=\"https:\/\/pypi.org\/project\/fpdf2\/\" target=\"_blank\">Python FPDF2<\/a><\/strong> library &amp; <strong><a rel=\"noreferrer noopener\" href=\"https:\/\/stellarium-web.org\/\" target=\"_blank\">Stellarium <\/a><\/strong> to check\/verify  if the setup is correct<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Create PDF Tables with Python FPDF2 video <\/h3>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n <iframe title=\"Create PDF Tables with Python FPDF2\" width=\"678\" height=\"381\" data-src=\"https:\/\/www.youtube.com\/embed\/euNvxWaRQMY?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p>Github <strong><a rel=\"noreferrer noopener\" href=\"https:\/\/github.com\/bvalgard\/create-pdf-with-python-fpdf2\" target=\"_blank\">repo for code<\/a><\/strong> for video above: <br>Sending Emails With Python Including Attachments (New Method for GMail &#8211; 2022):<\/p>\n\n\n\n<figure class=\"wp-block-embed is-type-video is-provider-youtube wp-block-embed-youtube wp-embed-aspect-16-9 wp-has-aspect-ratio\"><div class=\"wp-block-embed__wrapper\">\n<iframe title=\"Sending Emails With Python Including Attachments (New Method for GMail - 2022)\" width=\"678\" height=\"381\" data-src=\"https:\/\/www.youtube.com\/embed\/Sddnn6dpqk0?feature=oembed\" frameborder=\"0\" allow=\"accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share\" allowfullscreen src=\"data:image\/svg+xml;base64,PHN2ZyB3aWR0aD0iMSIgaGVpZ2h0PSIxIiB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciPjwvc3ZnPg==\" class=\"lazyload\" data-load-mode=\"1\"><\/iframe>\n<\/div><\/figure>\n\n\n\n<p><strong><a rel=\"noreferrer noopener\" href=\"https:\/\/drive.google.com\/drive\/folders\/1lhzFUPCNpMfvGSYKeuiVlYmlBo9G4Icd?usp=sharing\" target=\"_blank\">LINK <\/a><\/strong>to my Python Script Files: <br>The last part of the procedure was to automate the task.<br>Use Task Scheduler &#8211; setup new task. I had some difficulty getting this to run on my PC but it works fine on my server. <\/p>\n","protected":false},"excerpt":{"rendered":"<p>After creating a visualisation of planets orbiting in the solar system I wanted to see if I could create a daily Epheremis of planetary bodies for my particular location with Altitude &amp; Azimuth locations at hourly intervals and then send it to myself via an email so that I could access it on my mobile [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":9564,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[480,204,34],"tags":[],"class_list":["post-9558","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-astronomy","category-automation","category-python"],"featured_image_src":"https:\/\/max-drake.cc\/wp-content\/uploads\/2023\/04\/1.jpg","featured_image_src_square":"https:\/\/max-drake.cc\/wp-content\/uploads\/2023\/04\/1.jpg","author_info":{"display_name":"Max Drake","author_link":"https:\/\/max-drake.cc\/?author=1"},"_links":{"self":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/posts\/9558","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=9558"}],"version-history":[{"count":1,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/posts\/9558\/revisions"}],"predecessor-version":[{"id":9561,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/posts\/9558\/revisions\/9561"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=\/wp\/v2\/media\/9564"}],"wp:attachment":[{"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9558"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9558"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/max-drake.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9558"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}