From 0803754e05193fec8be90ca54229102af7c8ed9c Mon Sep 17 00:00:00 2001 From: korrio Date: Mon, 2 Jan 2023 16:25:06 +0700 Subject: [PATCH 1/3] enable FastAPI to get results with RESTful method --- __pycache__/main.cpython-39.pyc | Bin 0 -> 2230 bytes main.py | 91 ++++++++++++++++++++++++++++++++ 2 files changed, 91 insertions(+) create mode 100644 __pycache__/main.cpython-39.pyc create mode 100644 main.py diff --git a/__pycache__/main.cpython-39.pyc b/__pycache__/main.cpython-39.pyc new file mode 100644 index 0000000000000000000000000000000000000000..7f659a434ac113102fc8e494597b94574023d4f6 GIT binary patch literal 2230 zcma)-&u<$=6vt;~e|o)kT&S7`3Y1WwE{*M^<(G&mD%#Q_l%gc4!lJUao=LLp+Uv|t zTbj+#!(5S&dPCxt6Ys4}^8*fDYrme~^X9$xnT;xyfWY(X z&#mav}HwkWn)iQRMB4kg0cCT&-^Lyy}d z${p@LAltO<7cCyN_`FoKl!}&ML`A^MKT{s^$^#olmN{J^_3AU&lPuM#@h(M~I{(!b zD289GTwPig*&yv_Vuv=nIA-s|pz;~K85{@fBk-D|3iD4t7FrP8@bb~oZXqS@q(x})`v#Qz+Ky@NX_uEc`JT<-J~H>UKlDc=FX<8wW=J0BK(jkk{<8T{2g4Hd z1S-&_ZOY5HZ26Ze!??-(Z3-(K|CZ(DJk+7~bil)DqC#EfrD?EenkF+;E) z>JK#?Ry3pqC7ZLVs_8bA)Rd;UJFomuq{7nHYmH{%|NiaX4GhsjYhht-eqruRtD(MA zb=NqTt}L&t8f*31RpYE)UcPwIl#9R4xFZ->zC6FO+J^os%NKTRoN9=nvI|jo{$Kzx z@mJu@4uh-{O|FMI1xv|@{KPixm2uWQp~lISj0aDcVU3od$!;=9Oa>DyCNYFR?G4Vo z4)wp`C0i%fh3XWi>5S8(v6!UYD9O%2;osp!!ir~Tm_&JoW*ORnJ-u$)SE8@#HDj+Q z=?&v%sZ@d+mS)BtL~6tMH=<1Rqn87E2a3Tdna zdj0pmj3^p`2lppk0?VxMQFe5t+LRdh3YBS&W*2t9>QG{eX$DL& zAk&(VX=_%H=_u=_J#@4KWV#bFUFB(KLZ&w%(?hNbGX4LMdFKF`E|6K$a8d3d6G$xh zD+5nRCNgFNnNK$#>2MeTnIX_vo{+gS=59RyIhmEbs;j!B!-C9;uIwT6cUT8V1u~%@ z$b6)&A&f1^JPkxz1(`LtarTjUH#UMaIe*oKo=i3YK0)IR;WcWZbn>_97*b zVfhBiag;YvW>MZkIf3#v$~!3UqMSsjqntu{4+YbC%+i$n7|Ly5ZHP{R&K!0%P?{($ z6vRo+qb#7DK{< 2: + for i, d in enumerate(data[1:]): + row[dtype + '_' + str(i + 1)] = d + else: + row[dtype] = data[1] + + + rows.append(row) + print(rows) + return JSONResponse(content=rows[0]) + +@app.get("/date/{date_id}") +def get_lotto_date(date_id: str): + the_file = """./lottonumbers/{0}.txt""".format(date_id) + files = glob.glob(the_file) + files = sorted(files) + rows = [] + + need_dtypes = [ + 'FIRST', + 'TWO', + 'THREE', + 'THREE_FIRST', + 'THREE_LAST' + ] + for file in files: + + date = os.path.basename(file).replace('.txt', '') + + with open(file, 'r') as f: + lines = [l.strip() for l in f.readlines()] + + row = {'date': date} + for line in lines[1:]: + data = line.split() + + dtype = data[0] + if dtype not in need_dtypes: + continue + + dtype = dtype.lower() + if len(data) > 2: + for i, d in enumerate(data[1:]): + row[dtype + '_' + str(i + 1)] = d + else: + row[dtype] = data[1] + + + rows.append(row) + print(rows) + return JSONResponse(content=rows[0]) \ No newline at end of file From 46cfdb2533bb85fbf8f5facf2e0c7576288dde78 Mon Sep 17 00:00:00 2001 From: korrio Date: Mon, 2 Jan 2023 16:29:46 +0700 Subject: [PATCH 2/3] add README-fastapi.md --- .gitignore | 1 + README-fastapi.md | 48 ++++++++++++++++++++++++++++++++ __pycache__/main.cpython-39.pyc | Bin 2230 -> 0 bytes main.py | 1 - 4 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100644 README-fastapi.md delete mode 100644 __pycache__/main.cpython-39.pyc diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..ba0430d --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +__pycache__/ \ No newline at end of file diff --git a/README-fastapi.md b/README-fastapi.md new file mode 100644 index 0000000..1cae7d4 --- /dev/null +++ b/README-fastapi.md @@ -0,0 +1,48 @@ +# thai-lotto-archive-fastapi +Archive of winning Thai lottery numbers since 2007. All data are sourced from kapook.com, sanook.com, and other sources. + +## Install dependencies +
+ +```console +$ pip install fastapi + +---> 100% +``` + +
+ +You will also need an ASGI server, for production such as Uvicorn or Hypercorn. + +
+ +```console +$ pip install "uvicorn[standard]" + +---> 100% +``` + +
+ +### Run it + +Run the server with: + +
+ +```console +$ uvicorn main:app --reload + +INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) +INFO: Started reloader process [28720] +INFO: Started server process [28722] +INFO: Waiting for application startup. +INFO: Application startup complete. +``` + +
+ +### GET it + +- http://127.0.0.1:8000/latest +- http://127.0.0.1:8000/date/2022-12-16 diff --git a/__pycache__/main.cpython-39.pyc b/__pycache__/main.cpython-39.pyc deleted file mode 100644 index 7f659a434ac113102fc8e494597b94574023d4f6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 2230 zcma)-&u<$=6vt;~e|o)kT&S7`3Y1WwE{*M^<(G&mD%#Q_l%gc4!lJUao=LLp+Uv|t zTbj+#!(5S&dPCxt6Ys4}^8*fDYrme~^X9$xnT;xyfWY(X z&#mav}HwkWn)iQRMB4kg0cCT&-^Lyy}d z${p@LAltO<7cCyN_`FoKl!}&ML`A^MKT{s^$^#olmN{J^_3AU&lPuM#@h(M~I{(!b zD289GTwPig*&yv_Vuv=nIA-s|pz;~K85{@fBk-D|3iD4t7FrP8@bb~oZXqS@q(x})`v#Qz+Ky@NX_uEc`JT<-J~H>UKlDc=FX<8wW=J0BK(jkk{<8T{2g4Hd z1S-&_ZOY5HZ26Ze!??-(Z3-(K|CZ(DJk+7~bil)DqC#EfrD?EenkF+;E) z>JK#?Ry3pqC7ZLVs_8bA)Rd;UJFomuq{7nHYmH{%|NiaX4GhsjYhht-eqruRtD(MA zb=NqTt}L&t8f*31RpYE)UcPwIl#9R4xFZ->zC6FO+J^os%NKTRoN9=nvI|jo{$Kzx z@mJu@4uh-{O|FMI1xv|@{KPixm2uWQp~lISj0aDcVU3od$!;=9Oa>DyCNYFR?G4Vo z4)wp`C0i%fh3XWi>5S8(v6!UYD9O%2;osp!!ir~Tm_&JoW*ORnJ-u$)SE8@#HDj+Q z=?&v%sZ@d+mS)BtL~6tMH=<1Rqn87E2a3Tdna zdj0pmj3^p`2lppk0?VxMQFe5t+LRdh3YBS&W*2t9>QG{eX$DL& zAk&(VX=_%H=_u=_J#@4KWV#bFUFB(KLZ&w%(?hNbGX4LMdFKF`E|6K$a8d3d6G$xh zD+5nRCNgFNnNK$#>2MeTnIX_vo{+gS=59RyIhmEbs;j!B!-C9;uIwT6cUT8V1u~%@ z$b6)&A&f1^JPkxz1(`LtarTjUH#UMaIe*oKo=i3YK0)IR;WcWZbn>_97*b zVfhBiag;YvW>MZkIf3#v$~!3UqMSsjqntu{4+YbC%+i$n7|Ly5ZHP{R&K!0%P?{($ z6vRo+qb#7DK{< Date: Mon, 2 Jan 2023 16:32:48 +0700 Subject: [PATCH 3/3] add docs to README.md --- README-fastapi.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README-fastapi.md b/README-fastapi.md index 1cae7d4..433269a 100644 --- a/README-fastapi.md +++ b/README-fastapi.md @@ -44,5 +44,6 @@ INFO: Application startup complete. ### GET it +- http://127.0.0.1:8000/docs - http://127.0.0.1:8000/latest - http://127.0.0.1:8000/date/2022-12-16