Introduction
Introduction Statistics Contact Development Disclaimer Help
tscrape_plain.c - tscrape - twitter scraper (not working anymore)
git clone git://git.codemadness.org/tscrape
Log
Files
Refs
README
LICENSE
---
tscrape_plain.c (1854B)
---
1 #include <sys/types.h>
2
3 #include <err.h>
4 #include <locale.h>
5 #include <stdio.h>
6 #include <string.h>
7 #include <time.h>
8
9 #include "util.h"
10
11 static time_t comparetime;
12 static char *line;
13 static size_t linesize;
14
15 static void
16 printfeed(FILE *fp, const char *feedname)
17 {
18 char *fields[FieldLast];
19 struct tm *tm;
20 time_t parsedtime;
21 ssize_t linelen;
22
23 while ((linelen = getline(&line, &linesize, fp)) > 0) {
24 if (line[linelen - 1] == '\n')
25 line[--linelen] = '\0';
26 if (!parseline(line, fields))
27 break;
28
29 parsedtime = 0;
30 if (strtotime(fields[FieldUnixTimestamp], &parsedtime))
31 continue;
32 if (!(tm = localtime(&parsedtime)))
33 err(1, "localtime");
34
35 if (parsedtime >= comparetime)
36 putchar('N');
37 else
38 putchar(' ');
39 if (fields[FieldRetweetid][0])
40 putchar('R');
41 else
42 putchar(' ');
43 putchar(' ');
44
45 if (feedname[0])
46 printf("%-15.15s ", feedname);
47
48 fprintf(stdout, "%04d-%02d-%02d %02d:%02d ",
49 tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday,
50 tm->tm_hour, tm->tm_min);
51
52 printutf8pad(stdout, fields[FieldItemFullname], 25, ' ');
53 fputs(" ", stdout);
54 fputs(fields[FieldText], stdout);
55 putchar('\n');
56 }
57 }
58
59 int
60 main(int argc, char *argv[])
61 {
62 FILE *fp;
63 char *name;
64 int i;
65
66 if (pledge("stdio rpath", NULL) == -1)
67 err(1, "pledge");
68
69 setlocale(LC_CTYPE, "");
70
71 if (pledge(argc == 1 ? "stdio" : "stdio rpath", NULL) == -1)
72 err(1, "pledge");
73
74 if ((comparetime = time(NULL)) == -1)
75 err(1, "time");
76 /* 1 day is old news */
77 comparetime -= 86400;
78
79 if (argc == 1) {
80 printfeed(stdin, "");
81 } else {
82 for (i = 1; i < argc; i++) {
83 if (!(fp = fopen(argv[i], "r")))
84 err(1, "fopen: %s", argv[i]);
85 name = ((name = strrchr(argv[i], '/'))) ? name +…
86 printfeed(fp, name);
87 if (ferror(fp))
88 err(1, "ferror: %s", argv[i]);
89 fclose(fp);
90 }
91 }
92 return 0;
93 }
You are viewing proxied material from codemadness.org. The copyright of proxied material belongs to its original authors. Any comments or complaints in relation to proxied material should be directed to the original authors of the content concerned. Please see the disclaimer for more details.