-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopendata.h
103 lines (80 loc) · 2.46 KB
/
opendata.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* cliFuel
* Copyright (C) 2020-2022 Marco Magliano
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef OPENDATA_H_INCLUDED
#define OPENDATA_H_INCLUDED
#define _GNU_SOURCE 1
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <ctype.h>
#include <log.h>
#include <dmt.h>
#include <strsplit.h>
#include <curl/curl.h>
#include <csvparser.h>
#include <time.h>
#include "version.h"
#define CACHE_DIR ".clifuel-cache"
#define ANAGRAFIA_IMPIANTI_FILE "anagrafica_impianti_%y_%m_%d.csv"
#define PREZZI_FILE "prezzi_%y_%m_%d.csv"
#define ANAGRAFIA_IMPIANTI_URL "https://www.mise.gov.it/images/exportCSV/anagrafica_impianti_attivi.csv"
#define PREZZI_URL "https://www.mise.gov.it/images/exportCSV/prezzo_alle_8.csv"
#define FILE_SEPARATOR ";"
#define FILE_HEADER false
#define QUERY_LIST_SEPATATOR ","
#ifdef COLOR
#define COLOR_START_PATTERN(c) "\e[1;" #c "m"
#define COLOR_END_PATTERN "\e[0m"
#endif // COLOR
#define QUERY_PREFIX_ID "id:"
#define QUERY_PREFIX_PROV "prov:"
#define QUERY_PREFIX_LIST "list:"
enum item_age {UNDEF = 0, NEW, OK, OLD };
enum service {SELF = 0, NOT_SELF};
typedef struct station {
int id;
char* name;
char* type;
char* address;
char* town;
struct station* next;
} station_t;
typedef struct price {
int id;
char* fuelDesc;
float price;
enum service self;
char* lastUpdate;
enum item_age is_old;
struct price* next;
} price_t;
typedef struct {
struct station *station;
struct price *price;
} opendata_result_t;
bool download(const char*, const char*);
station_t* stationFinder(char*, char*, bool, char*);
price_t* priceFinder(char*, char*, bool, station_t*, char*);
void freeStationList(station_t*);
void freePriceList(price_t*);
enum item_age is_old_data(const char*);
#ifdef COLOR
char* make_alert(const price_t*);
#endif // COLOR
#endif // OPENDATA_H_INCLUDED