{"id":951,"date":"2014-09-10T00:54:33","date_gmt":"2014-09-10T00:54:33","guid":{"rendered":"http:\/\/poojanwagh.opalstacked.com\/techblog\/?p=951"},"modified":"2014-09-10T00:55:48","modified_gmt":"2014-09-10T00:55:48","slug":"fun-with-schoolspeak","status":"publish","type":"post","link":"https:\/\/tech.poojanblog.com\/blog\/progamming\/fun-with-schoolspeak\/","title":{"rendered":"Fun with SchoolSpeak"},"content":{"rendered":"<p>So, our school has adopted SchoolSpeak as their online platform. This includes lunch orders, and I&#8217;ve been asked to help the administration out with some summary reports (at least until SchoolSpeak can directly support what we need).<\/p>\n<p>Basically, I need to figure out how much money was made each day of the month, totaled by week-day.<\/p>\n<p>Unfortunately, the only view that has this information is a summary of orders on a day-by-day basis. So, I need to:<\/p>\n<ol>\n<li>Download each day for the month<\/li>\n<li>For each day, grab the total and keep it in a running sum (categorized by week-day)<\/li>\n<li>Email the result to the admin<\/li>\n<\/ol>\n<p>For #1, I have a single day download-able via <a href=\"http:\/\/www.seleniumhq.org\/\">Selenium<\/a>. (Which rocks by the way!) So, it&#8217;s just a matter of making it iterate over days of the month. To do that, I need to:<\/p>\n<ol>\n<li>Accept (probably from the command-line) an month\/year combination<\/li>\n<li>Figure out how many days there are in that month<\/li>\n<li>Run over a range of days and download each day. (Luckily the download is already implemented as a function which takes a m\/d\/y as an argument; I will probably refactor it to take a datetime argument.)<\/li>\n<\/ol>\n<p>For #1, I&#8217;ll use <a title=\"Stack Overflow on parsing date with argparse\" href=\"http:\/\/stackoverflow.com\/questions\/8198162\/pass-date-to-a-variable-from-the-script\" target=\"_blank\">argparse<\/a>, and it looks like so:<\/p>\n<pre>\r\ndef get_date(s):\r\n  ymd = s.split('-')\r\n  if len(ymd) == 2:\r\n    return datetime.datetime.strptime(s, '%Y-%m')\r\n  if len(ymd) == 3:\r\n    return datetime.datetime.strptime(s, '%Y-%m-%d')\r\n<\/pre>\n<p>The above accepts both year-month-day and year-month format. I intended for a year-month to be the entire month, but the datetime module will parse it as year-month-1 (1st of the month), so I&#8217;ll need to add a command-line parameter to iterate over the month.<\/p>\n<p>Speaking of which, how do I figure out how many days in a month? Turns out there&#8217;s a <a href=\"https:\/\/docs.python.org\/2\/library\/calendar.html\">calendar<\/a> module for that. And it has an iterator over days of the month. Sweet!<\/p>\n<p>Knowing that, let&#8217;s make my get-date function always return an iteratable of datetime.date&#8217;s:<\/p>\n<pre>\r\ndef get_date(s):\r\n  ymd = s.split('-')\r\n  if len(ymd) == 2:\r\n    return calendar.Calendar.itermonthdays(int(ymd[0]), int(ymd[1]))\r\n  if len(ymd) == 3:\r\n    return [ datetime.date.strptime(s, '%Y-%m-%d') ]\r\n<\/pre>\n<p>More to follow&#8230;<\/p>\n<div class='wp_likes' id='wp_likes_post-951'><a class='like' href=\"javascript:wp_likes.like(951);\" title='' ><img data-recalc-dims=\"1\" decoding=\"async\" src=\"https:\/\/i0.wp.com\/tech.poojanblog.com\/blog\/wp-content\/plugins\/wp-likes\/images\/like.png\" alt='' border='0'\/><\/a><span class='text'>Be the first to like.<\/span><\/p>\n<div class='like' ><a href=\"javascript:wp_likes.like(951);\">Like<\/a><\/div>\n<div class='unlike' ><a href=\"javascript:wp_likes.unlike(951);\">Unlike<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>So, our school has adopted SchoolSpeak as their online platform. This includes lunch orders, and I&#8217;ve been asked to help the administration out with some summary reports (at least until SchoolSpeak can directly support what we need). Basically, I need to figure out how much money was made each day of the month, totaled by [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[48],"tags":[235,234,236,46,237],"class_list":["post-951","post","type-post","status-publish","format-standard","hentry","category-progamming","tag-argparse","tag-csv","tag-datetime","tag-python","tag-schoolspeak"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/posts\/951","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/comments?post=951"}],"version-history":[{"count":6,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/posts\/951\/revisions"}],"predecessor-version":[{"id":958,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/posts\/951\/revisions\/958"}],"wp:attachment":[{"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/media?parent=951"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/categories?post=951"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/tech.poojanblog.com\/blog\/wp-json\/wp\/v2\/tags?post=951"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}