Merge pull request #28 from rmeertens/master

Input now downloads files from Github
This commit is contained in:
Peter Norvig
2017-12-30 21:38:26 -08:00
committed by GitHub

View File

@@ -38,6 +38,9 @@
"%matplotlib inline\n", "%matplotlib inline\n",
"import matplotlib.pyplot as plt\n", "import matplotlib.pyplot as plt\n",
"\n", "\n",
"import os\n",
"import urllib.request\n",
"\n",
"import re\n", "import re\n",
"import numpy as np\n", "import numpy as np\n",
"import math\n", "import math\n",
@@ -66,7 +69,16 @@
"\n", "\n",
"def Input(day, year=2017):\n", "def Input(day, year=2017):\n",
" \"Open this day's input file.\"\n", " \"Open this day's input file.\"\n",
" return open('data/advent{}/input{}.txt'.format(year, day))\n", " directory = 'advent{}/'.format(year)\n",
" filename = directory+'input{}.txt'.format(day)\n",
" try:\n",
" return open(filename)\n",
" except FileNotFoundError:\n",
" if not os.path.exists(directory):\n",
" os.makedirs(directory)\n",
"\n",
" urllib.request.urlretrieve(\"https://raw.githubusercontent.com/norvig/pytudes/master/data/\" + filename, filename)\n",
" return Input(day)\n",
"\n", "\n",
"def Inputstr(day, year=2017): \n", "def Inputstr(day, year=2017): \n",
" \"The contents of this day's input file as a str.\"\n", " \"The contents of this day's input file as a str.\"\n",