gusti-adli commited on
Commit
a59e1e1
β€’
1 Parent(s): 286aee6

upload all

Browse files
Files changed (5) hide show
  1. Dockerfile +36 -0
  2. README.md +5 -4
  3. app/app.py +59 -0
  4. app/assets/css/styles.css +5 -0
  5. app/assets/img/dummy.txt +0 -0
Dockerfile ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #Grab python=3.9-slim-buster image
2
+ FROM python:3.9-slim-buster
3
+
4
+
5
+ # Copy code to container
6
+ COPY . .
7
+
8
+ # RUN apt-get update
9
+ RUN apt-get update && apt-get install -y build-essential wget python3-dev python3-pip gcc
10
+ # openldap-dev libffi-dev jpeg-dev zlib-dev libmemcached-dev gcc libc-dev g++ libxml2 libxslt libxslt-dev
11
+
12
+ # TA-Lib
13
+ RUN wget http://prdownloads.sourceforge.net/ta-lib/ta-lib-0.4.0-src.tar.gz && \
14
+ tar -xvzf ta-lib-0.4.0-src.tar.gz && \
15
+ cd ta-lib/ && \
16
+ ./configure --prefix=/usr && \
17
+ make && \
18
+ make install && \
19
+ cd ..
20
+ RUN rm -R ta-lib ta-lib-0.4.0-src.tar.gz
21
+
22
+ # Move working directory
23
+ WORKDIR /app
24
+
25
+ # Install python depencies
26
+ RUN pip3 install --upgrade pip && pip3 install --no-cache-dir -q -r requirements.txt
27
+
28
+ # Expose is NOT supported by Heroku
29
+ # EXPOSE 5000
30
+
31
+ # Run the image as a non-root user
32
+ RUN adduser myuser
33
+ USER myuser
34
+
35
+ # Run the app. CMD is required to run on Heroku
36
+ CMD gunicorn --bind 0.0.0.0:5000 app:app
README.md CHANGED
@@ -1,9 +1,10 @@
1
  ---
2
- title: Screener Saham Demo
3
- emoji: 🐒
4
- colorFrom: purple
5
- colorTo: gray
6
  sdk: docker
 
7
  pinned: false
8
  license: apache-2.0
9
  ---
 
1
  ---
2
+ title: Screener Saham IDX Demo
3
+ emoji: πŸ“ˆ
4
+ colorFrom: red
5
+ colorTo: green
6
  sdk: docker
7
+ app_port: 5000
8
  pinned: false
9
  license: apache-2.0
10
  ---
app/app.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, render_template, request
2
+ from helper_script import get_tickers, get_data, plot_candlestick
3
+ from update_database import update_database, get_last_update_time
4
+ from bokeh.resources import INLINE
5
+ import json
6
+
7
+ app = Flask(__name__)
8
+
9
+ # load patterns file
10
+ with open("dataset/patterns.json") as f:
11
+ patterns = json.load(f)
12
+ # sort `patterns` by value
13
+ patterns = dict(sorted(patterns.items(), key=lambda item: item[1]))
14
+
15
+ last_update_time = get_last_update_time()
16
+
17
+ @app.route("/", methods=["GET", "POST"])
18
+ def home():
19
+ global last_update_time
20
+ pattern = request.args.get("pattern", None)
21
+ if request.method == "POST":
22
+ update_database()
23
+ last_update_time = get_last_update_time()
24
+ return render_template("index.html", patterns=patterns, selected=pattern, last_update_time=last_update_time)
25
+ if pattern:
26
+ return plot(pattern)
27
+ else:
28
+ return render_template("index.html", patterns=patterns, selected=False, last_update_time=last_update_time)
29
+
30
+
31
+ def plot(pattern):
32
+ print(pattern)
33
+ plot_divs, plot_scripts = [], []
34
+ tickers = get_tickers(patterns[pattern])
35
+ print(len(tickers))
36
+ if len(tickers) == 0:
37
+ return render_template("no_pattern_found.html", patterns=patterns, selected=pattern)
38
+ else:
39
+ for i, kode in enumerate(tickers):
40
+ print(f"{kode}\t\t {i}/{len(tickers)}")
41
+ df, nama = get_data(kode, patterns[pattern])
42
+ if len(df[["Open", "High", "Low", "Close"]].tail(3).drop_duplicates(keep=False)) > 0:
43
+ plot_script, plot_div = plot_candlestick(df, nama, kode)
44
+ plot_scripts.append(plot_script)
45
+ plot_divs.append(plot_div)
46
+ return render_template(
47
+ "plot.html",
48
+ patterns=patterns,
49
+ selected=pattern,
50
+ js_resources = INLINE.render_js(),
51
+ css_resources = INLINE.render_css(),
52
+ plot_divs = plot_divs,
53
+ plot_scripts = plot_scripts,
54
+ last_update_time=last_update_time
55
+ )
56
+
57
+
58
+ if __name__ == "__main__":
59
+ app.run(debug=True)
app/assets/css/styles.css ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ div#loading {
2
+ width: 50%;
3
+ height: 50%;
4
+ cursor: wait;
5
+ }
app/assets/img/dummy.txt ADDED
File without changes