Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
neeharv committed May 23, 2015
0 parents commit a5f62bd
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/target
lib/*
/.emacs.desktop
/.emacs.desktop.lock
.lein-repl-history
38 changes: 38 additions & 0 deletions README.md
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

8 changes: 8 additions & 0 deletions project.clj
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"]])
56 changes: 56 additions & 0 deletions src/scrape-mf.clj
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)))

0 comments on commit a5f62bd

Please sign in to comment.