-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a5f62bd
Showing
4 changed files
with
107 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
/target | ||
lib/* | ||
/.emacs.desktop | ||
/.emacs.desktop.lock | ||
.lein-repl-history |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Invst | ||
|
||
Invst is a terribly named portfolio management software. Currently it supports tracking Mutual Fund NAVs daily only. | ||
|
||
This is an expirement with Clojure + Elasticsearch. | ||
|
||
### Version | ||
0.0.1 | ||
|
||
### Tech | ||
|
||
Invst uses the following not-fancy code to work | ||
|
||
* Clojure | ||
* Enlive web scraper | ||
* Elastic search | ||
* Kibana | ||
|
||
### Installation | ||
|
||
You need Gulp installed globally: | ||
|
||
```sh | ||
$ npm i -g gulp | ||
``` | ||
### Todo's | ||
|
||
- Store user's investment details | ||
- Move elasticsearch and URL parsing to config files | ||
- Remove tutorial code | ||
- Write tests | ||
- Auto run using cron (?) | ||
|
||
License | ||
---- | ||
|
||
MIT | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
(defproject invst "0.0.1" | ||
:description "Invst - a portfolio management software" | ||
:dependencies [[org.clojure/clojure "1.5.1"] | ||
[enlive "1.1.1"] | ||
[ring "1.2.0"] | ||
[net.cgrand/moustache "1.1.0"] | ||
[clj-http "1.1.2"] | ||
[clojurewerkz/elastisch "2.1.0"]]) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
(ns tutorial.scrape-mf | ||
(:require [net.cgrand.enlive-html :as html]) | ||
(:require [clj-http.client :as client]) | ||
(:require [clojurewerkz.elastisch.rest :as esr] | ||
[clojurewerkz.elastisch.rest.index :as esi] | ||
[clojurewerkz.elastisch.rest.document :as esd])) | ||
|
||
(def ^:dynamic *base-url* "https://www.amfiindia.com/modules/NAVList") | ||
|
||
(defn -main [& args] | ||
(let [conn (esr/connect "http://127.0.0.1:9200") | ||
mapping-types {"mutual-fund" {:properties { | ||
:name {:type "string" :store "yes"} | ||
:isin_growth_option {:type "string" :store "yes"} | ||
:isin_dividend_option {:type "string"} | ||
:nav {:type "float"} | ||
:repurchase_price {:type "float"} | ||
:sale_price {:type "float"} | ||
:date {:type "date"}}}}] | ||
(esi/create conn "development" :mappings mapping-types))) | ||
(defn createDoc [[mf_name isin_growth_option isin_dividend_option nav repurchase_price sale_price date]] | ||
(def conn (esr/connect "http://127.0.0.1:9200")) | ||
(println conn) | ||
(def doc { | ||
:name mf_name | ||
:isin_growth_option isin_growth_option | ||
:isin_dividend_option isin_dividend_option | ||
:nav (read-string nav) | ||
:repurchase_price (read-string repurchase_price) | ||
:sale_price (read-string sale_price)}) | ||
(println doc) | ||
(esd/create conn "development" "mutual-fund" doc)) | ||
(defn submit-form [url] | ||
(html/html-snippet (:body (client/post url {:form-params {:MFName "10-27"}})))) | ||
|
||
(defn fetch-url [url] | ||
(html/html-resource (java.net.URL. url))) | ||
|
||
(defn mf-data [] | ||
(map html/text (html/select (submit-form *base-url*) [:td]))) | ||
|
||
(defn store-mf [] | ||
(-main) | ||
(map createDoc (partition 7 (mf-data)))) | ||
|
||
(defn print-mf [] | ||
(doseq [line (map (fn [[ | ||
mf_name | ||
isin_growth_option | ||
isin_dividend_option | ||
nav | ||
repurchase_price | ||
sale_price date]] | ||
(str mf_name"," isin_growth_option"," isin_dividend_option"," nav"," repurchase_price"," sale_price"," date)) | ||
(partition 7 (mf-data)))] | ||
(println line))) |