diff options
| author | 2025-09-09 08:44:00 +0200 | |
|---|---|---|
| committer | 2025-09-09 08:44:00 +0200 | |
| commit | a23e5c29082d07ea84b34470f684717561d40970 (patch) | |
| tree | 92672caa36db274f9a5731706c93d6381bf679f6 /main.c | |
| parent | Added support for scheduled posts from the cmdline. (diff) | |
| download | penes-snac2-a23e5c29082d07ea84b34470f684717561d40970.tar.gz penes-snac2-a23e5c29082d07ea84b34470f684717561d40970.tar.xz penes-snac2-a23e5c29082d07ea84b34470f684717561d40970.zip | |
Set the scheduled date via the -d argument instead of a envvar.
Diffstat (limited to 'main.c')
| -rw-r--r-- | main.c | 42 |
1 files changed, 24 insertions, 18 deletions
| @@ -807,34 +807,40 @@ int main(int argc, char *argv[]) | |||
| 807 | xs *attl = xs_list_new(); | 807 | xs *attl = xs_list_new(); |
| 808 | const char *fn = NULL; | 808 | const char *fn = NULL; |
| 809 | const char *in_reply_to = NULL; | 809 | const char *in_reply_to = NULL; |
| 810 | const char **next = NULL; | 810 | const char **arg_irt = NULL; |
| 811 | int arg_date = 0; | ||
| 811 | xs *post_date = NULL; | 812 | xs *post_date = NULL; |
| 812 | 813 | ||
| 813 | const char *env_date = getenv("SNAC_POST_DATE"); | ||
| 814 | if (env_date) { | ||
| 815 | /* convert to ISO */ | ||
| 816 | time_t t = xs_parse_localtime(env_date, "%Y%m%d%H%M%S"); | ||
| 817 | |||
| 818 | if (t == 0) { | ||
| 819 | fprintf(stderr, "Invalid $SNAC_POST_DATE format (must be YYYYmmddHHMMSS)\n"); | ||
| 820 | return 1; | ||
| 821 | } | ||
| 822 | |||
| 823 | post_date = xs_str_iso_date(t); | ||
| 824 | } | ||
| 825 | |||
| 826 | /* iterate possible attachments */ | 814 | /* iterate possible attachments */ |
| 827 | while ((fn = GET_ARGV())) { | 815 | while ((fn = GET_ARGV())) { |
| 828 | FILE *f; | 816 | FILE *f; |
| 829 | 817 | ||
| 830 | if (next) { | 818 | if (arg_irt) { |
| 831 | *next = fn; | 819 | *arg_irt = fn; |
| 832 | next = NULL; | 820 | arg_irt = NULL; |
| 821 | } | ||
| 822 | else | ||
| 823 | if (arg_date) { | ||
| 824 | /* convert to ISO */ | ||
| 825 | time_t t = xs_parse_localtime(fn, "%Y%m%d%H%M%S"); | ||
| 826 | |||
| 827 | if (t == 0) { | ||
| 828 | fprintf(stderr, "Invalid scheduled date format (must be YYYYmmddHHMMSS)\n"); | ||
| 829 | return 1; | ||
| 830 | } | ||
| 831 | |||
| 832 | post_date = xs_str_iso_date(t); | ||
| 833 | arg_date = 0; | ||
| 833 | } | 834 | } |
| 834 | else | 835 | else |
| 835 | if (strcmp(fn, "-r") == 0) { | 836 | if (strcmp(fn, "-r") == 0) { |
| 836 | /* next argument is an inReplyTo */ | 837 | /* next argument is an inReplyTo */ |
| 837 | next = &in_reply_to; | 838 | arg_irt = &in_reply_to; |
| 839 | } | ||
| 840 | else | ||
| 841 | if (strcmp(fn, "-d") == 0) { | ||
| 842 | /* next argument is the schedule date */ | ||
| 843 | arg_date = 1; | ||
| 838 | } | 844 | } |
| 839 | else | 845 | else |
| 840 | if ((f = fopen(fn, "rb")) != NULL) { | 846 | if ((f = fopen(fn, "rb")) != NULL) { |