aboutsummarylogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--.SRCINFO2
-rw-r--r--PKGBUILD2
-rw-r--r--README.md7
-rw-r--r--api.c57
-rw-r--r--api.h8
-rw-r--r--main.c2
-rw-r--r--tick.18
7 files changed, 58 insertions, 28 deletions
diff --git a/.SRCINFO b/.SRCINFO
index c21822fb75b5..cc2cead19447 100644
--- a/.SRCINFO
+++ b/.SRCINFO
@@ -1,6 +1,6 @@
pkgbase = tick
pkgdesc = Command line stock and cryptocurrency portfolio tracker.
- pkgver = 1.6.1
+ pkgver = 1.6.2
pkgrel = 1
url = https://github.com/aokellermann/tick
arch = x86_64
diff --git a/PKGBUILD b/PKGBUILD
index 2cd3c46e1018..941ccab41660 100644
--- a/PKGBUILD
+++ b/PKGBUILD
@@ -1,7 +1,7 @@
# Maintainer: Antony Kellermann <aokellermann@gmail.com>
pkgname=tick
-pkgver=1.6.1
+pkgver=1.6.2
pkgrel=1
pkgdesc="Command line stock and cryptocurrency portfolio tracker."
arch=('x86_64')
diff --git a/README.md b/README.md
index b1317f3a3c0d..6008dedcbb66 100644
--- a/README.md
+++ b/README.md
@@ -41,6 +41,8 @@ you can run
```bash
$ tick news [symbol]
```
+If you wish to use spaces in your input, you can either surround the phrase
+with quotes or replace spaces with underscores.
Once installed, you may read the man page for more information.
@@ -55,5 +57,6 @@ not abuse the APIs by repeatedly requesting information. Read the provided
license for more information.
#### Future Ideas
* Command to get info about a security
-* More robust information in "check"
-* Historical support -- 7d/28d profits \ No newline at end of file
+* Historical support -- 7d/28d profits
+* Change portfolio structure to JSON format
+* Different ways to sort "check all" \ No newline at end of file
diff --git a/api.c b/api.c
index 475cb9f3efca..c314012237fd 100644
--- a/api.c
+++ b/api.c
@@ -166,6 +166,13 @@ double* coinmarketcap_get_price(char* ticker_name_string) {
}
void news_print_top_three(char* ticker_name_string) {
+ char* url_encoded_string = calloc(128, 1);
+ for (int i = 0, j = 0; i < 128; i++, j++) {
+ if (ticker_name_string[i] == '_' || ticker_name_string[i] == ' ') {
+ memcpy(&url_encoded_string[i], "%20", 3);
+ i += 2;
+ } else url_encoded_string[i] = ticker_name_string[j];
+ }
time_t now = time(NULL);
struct tm* ts;
char* yearchar = calloc(64, 1);
@@ -176,11 +183,10 @@ void news_print_top_three(char* ticker_name_string) {
char* news_api_string = calloc(256, sizeof(char));
sprintf(news_api_string, "%s&from=%s&q=%s",
"https://newsapi.org/v2/everything?sortBy=relevancy&pageSize=3&language=en&apiKey=1163c352d041460381f0a8273e60a9d1",
- yearchar, ticker_name_string);
+ yearchar, url_encoded_string);
free(yearchar);
+ free(url_encoded_string);
String* pString = api_curl_data(news_api_string, NULL);
- //printf("%s\n", pString->data);
- //printf("%s\n", news_api_string);
Json* jobj = json_tokener_parse(pString->data);
if (strtol(json_object_to_json_string(json_object_object_get(jobj, "totalResults")), NULL,
10) > 0)
@@ -199,21 +205,17 @@ void json_print_news(Json* jobj) {
10);
for (int i = 0; i < results && i < 3; i++) {
article = json_object_array_get_idx(article_list, (size_t) i);
- author_string = (char*) json_object_to_json_string(json_object_object_get(article, "author"));
- title_string = (char*) json_object_to_json_string(json_object_object_get(article, "title"));
- source_string = (char*) json_object_to_json_string(
- json_object_object_get(json_object_object_get(article, "source"), "name"));
+ author_string = (char*) strip_char(
+ (char*) json_object_to_json_string(json_object_object_get(article, "author")), '\\');
+ title_string = (char*) strip_char(
+ (char*) json_object_to_json_string(json_object_object_get(article, "title")), '\\');
+ source_string = (char*) strip_char((char*) json_object_to_json_string(
+ json_object_object_get(json_object_object_get(article, "source"), "name")), '\\');
date_string = (char*) json_object_to_json_string(json_object_object_get(article, "publishedAt"));
-
- url_string = (char*) json_object_to_json_string(json_object_object_get(article, "url"));
- char* url_final = calloc(strlen(url_string + 1), 1);
- for (int k = 0, j = 0; j < strlen(url_string); k++, j++) {
- if (url_string[j] == '\\' || url_string[j] == '\"')
- j++;
- url_final[k] = url_string[j];
- }
-
- char* shorten = (char*) google_shorten_link(url_final);
+ url_string = (char*) strip_char((char*) json_object_to_json_string(json_object_object_get(article, "url")),
+ '\\');
+ char* stripped = (char*) strip_char(url_string, '\"');
+ char* shortened = (char*) google_shorten_link(stripped);
printf("Title: %s Source: %s ", title_string, source_string);
if (strcmp(author_string, "null") != 0)
printf("Author: %s ", author_string);
@@ -222,9 +224,13 @@ void json_print_news(Json* jobj) {
date_string[12] = '\0';
printf("Date: %s ", date_string);
}
- printf("Url: %s\n", shorten);
- free(url_final);
- free((void*) shorten);
+ printf("Url: \"%s\"\n", shortened);
+ free(author_string);
+ free(title_string);
+ free(source_string);
+ free(url_string);
+ free(stripped);
+ free(shortened);
}
}
@@ -251,6 +257,17 @@ const char* google_shorten_link(char* url_string) {
return final;
}
+const char* strip_char(char* string, char c) {
+ size_t len = strlen(string);
+ char* final_string = calloc(len + 1, 1);
+ for (int i = 0, j = 0; j < (int) len; i++, j++) {
+ while (string[j] == c)
+ j++;
+ final_string[i] = string[j];
+ }
+ return final_string;
+}
+
void api_string_destroy(String** phString) {
String* pString = *phString;
free(pString->data);
diff --git a/api.h b/api.h
index 1163e173b70a..e11523e0d3fd 100644
--- a/api.h
+++ b/api.h
@@ -104,6 +104,14 @@ void json_print_news(Json* jobj);
const char* google_shorten_link(char* url_string);
/**
+ * Returns a string stripped of the given char
+ * @param string the string to strip the char from
+ * @param c the char to strip
+ * @return the stripped string
+ */
+const char* strip_char(char* string, char c);
+
+/**
* Destroys String object and frees memory
* @param phString the String to destroy
*/
diff --git a/main.c b/main.c
index d61ada13239d..1bc770970f9a 100644
--- a/main.c
+++ b/main.c
@@ -4,7 +4,7 @@
int main(int argc, char* argv[]) {
if (argc == 3 && strcmp(argv[1], "news") == 0) {
- if (strlen(argv[2]) <= 16 && strlen(argv[2]) > 1)
+ if (strlen(argv[2]) <= 32 && strlen(argv[2]) > 1)
news_print_top_three(argv[2]);
else printf("Input invalid length.\n");
return 0;
diff --git a/tick.1 b/tick.1
index 56f69aeadb8b..65eb5823595c 100644
--- a/tick.1
+++ b/tick.1
@@ -1,10 +1,10 @@
-.TH TICK "1" "January 2018" "Tick 1.6.1" "User Commands"
+.TH TICK "1" "January 2018" "Tick 1.6.2" "User Commands"
.SH NAME
Tick - Command line stock and cryptocurrency portfolio tracker.
.SH SYNOPSIS
-tick [OPTION]...
+tick COMMAND [ARGUMENTS]
.SH DESCRIPTION
Create your portfolio by adding your current holdings. Then, use the option "check" to get information on the current price.
@@ -34,7 +34,9 @@ News:
.TP
[news] [symbol]
Prints information on the top three news articles in the past 14 days. The article titles, sources, authors, dates, and URLs
-will be displayed. Technically, the input may be something completely unrelated to investing. This may be amended in the future.
+will be displayed. If you would like to use a space in your search, you must either use an underscore instead of the space or wrap
+your phrase in double quotes. Technically, the input may be something completely unrelated to investing. This may be amended
+in the future.
.SH FILES
.I ~/.tick_portfolio