diff options
author | Antony Kellermann | 2018-02-04 23:04:09 -0500 |
---|---|---|
committer | Antony Kellermann | 2018-02-04 23:04:09 -0500 |
commit | 6f95e055b66f0a0a92b141bd5ac33a93f780e5c9 (patch) | |
tree | 32085ece9d2458a56a23e961e267e613b119cc9f | |
parent | 7744aea198540aa707c35bcd364ddc3ea07c3f50 (diff) | |
download | aur-6f95e055b66f0a0a92b141bd5ac33a93f780e5c9.tar.gz |
Minor formatting fixes in news
-rw-r--r-- | .SRCINFO | 2 | ||||
-rw-r--r-- | PKGBUILD | 2 | ||||
-rw-r--r-- | README.md | 7 | ||||
-rw-r--r-- | api.c | 57 | ||||
-rw-r--r-- | api.h | 8 | ||||
-rw-r--r-- | main.c | 2 | ||||
-rw-r--r-- | tick.1 | 8 |
7 files changed, 58 insertions, 28 deletions
@@ -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 @@ -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 @@ -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); @@ -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 */ @@ -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; @@ -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 |