Created
January 4, 2013 07:28
-
-
Save alphaKAI/4450660 to your computer and use it in GitHub Desktop.
Nexus7 おんりーでかいてた てふてふ のリプライ機構(途中)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #include "my_lib.h" | |
| #include "twilib.h" | |
| /* | |
| post関数は本体のmaincをこぴぺして必要最低限のところまできりとった | |
| */ | |
| int post(char[100] post_string); | |
| void RemoveReturn(char *str, int size); | |
| int main(void) | |
| { | |
| int num; | |
| int i; | |
| int sum; | |
| int line; | |
| int retuen_ sum; | |
| int return_post; | |
| //自分のid | |
| char me_id[] = "@tefutefu_tyou"; | |
| //タイムラインを取得して保存したふぁいる | |
| char timeline[] = "timeline.txt"; | |
| char tmpf[] = "tmp.txt"; | |
| char filename[] = "data.txt"; | |
| //リプライ送信先 | |
| char re_id[100]; | |
| int return_strstr; | |
| int return_make; | |
| char *str; | |
| FILE *fp; | |
| i=1; | |
| num = check(timeline); | |
| if(num == 1){ | |
| line = how_line(timeline); | |
| } | |
| else if(num = 0){ | |
| printf("ERROR:\n"); | |
| printf("ファイルチェックに失敗しました\n"); | |
| printf("カレントディレクトリに\"%s\"が存在しません\n"); | |
| printf("終了します\n"); | |
| return 2; | |
| } | |
| else if(num!=0){ | |
| printf("ERROR:\n"); | |
| printf("check関数からの返り値が異常です\n"); | |
| printf("値:%d\n", num); | |
| printf("終了します\n"); | |
| return num; | |
| } | |
| //自分のid宛のリプライがあるかをチェック あった場合は返信 | |
| while(i=<line){ | |
| return_sum = ReturnStrings(timeline, i, str, 1000); | |
| switch(return_sum){ | |
| case -1: | |
| printf("ERROR:\n"); | |
| printf("ファイルチェックに失敗しました\n"); | |
| printf("文字列検索中のエラーです\n"); | |
| printf("終了します\n"); | |
| return -1; | |
| break; | |
| case -2: | |
| printf("ERROR:\n"); | |
| printf("ファイルからデータの取得に失敗しました\n"); | |
| printf("ファイル:%s 内 取得失敗行数:%d\n", timeline, i); | |
| printf("Debug:取得した文字列:\n%s\nデータは破損しています\n", str); | |
| printf("終了します\n"); | |
| return -2; | |
| break; | |
| case 0: | |
| printf("データ取得成功\n"); | |
| break; | |
| default: | |
| printf("ERROR:\n"); | |
| printf("原因不明のエラー\n"); | |
| printd("Debug:\n"); | |
| printf("返り値:%d\n", return_sum); | |
| printf("取得行数:%d\n", i); | |
| printf("取得文字列:%s\n", str); | |
| printf("終了します\n"); | |
| return return_sum; | |
| break; | |
| } | |
| //文字列検索処理 | |
| return_strstr = strstr(str, me_id); | |
| if(return_strstr!=NULL){ | |
| //正規表現で文字列からリプライ先のidを取得する | |
| //文章生成 | |
| return_make = make_string(filename, str,1000); | |
| sprintf(str, "%s %s", re_id, str); | |
| } | |
| //Reply投稿処理 | |
| return_post = post(str); | |
| if(return_post!=0){ | |
| printf("何かしらのエラーが発生してます\n"); | |
| printf("Error Code:%d\n", return_post); | |
| } | |
| i++; | |
| }/* 検索ここまで */ | |
| return 0; | |
| } | |
| void RemoveReturn(char *str, int size) | |
| { | |
| int i=0; | |
| while(str[i] != 0 && i != size) { | |
| if(str[i] == '\r' || str[i] == '\n') str[i] = 0; | |
| i++; | |
| } | |
| } | |
| int post(char[100] post_string) | |
| { | |
| int errcode = 0; | |
| char pin[20] = {0}; | |
| char *errcode_c = 0; | |
| FILE *access_token; | |
| char usr[20] = {0}, id[20] = {0}, token[150] = {0}, secret[150] = {0}; | |
| struct Twitter_consumer_token *c; | |
| struct Twitter_request_token *r; | |
| struct Twitter_access_token *a; | |
| c = (struct Twitter_consumer_token *) calloc(1, sizeof(struct Twitter_consumer_token)); | |
| r = (struct Twitter_request_token *) calloc(1, sizeof(struct Twitter_request_token)); | |
| a = (struct Twitter_access_token *) calloc(1, sizeof(struct Twitter_access_token)); | |
| char consumer_key[] = "9qjaaynB6iZ5jjbj77vQg"; | |
| char consumer_secret[] = "btaHirIHyJG9496n5nYlaaO4b3WyirxVo0Up3CsQ"; | |
| c->consumer_key = consumer_key; | |
| c->consumer_secret = consumer_secret; | |
| access_token = fopen("access_token.txt", "r"); | |
| sum=check(filename); | |
| if(sum==1){ | |
| access_token = fopen("access_token.txt", "ab"); | |
| } | |
| else{ | |
| access_token = fopen("access_token.txt", "wt"); | |
| } | |
| if(access_token == NULL) { | |
| printf("Error\n"); | |
| exit(0); | |
| } | |
| fprintf(access_token, "%s\n%s\n%s\n%s\n%s\n", a->screen_name, a->user_id, a->access_token, a->access_secret, a->pin); | |
| fclose(access_token); | |
| } | |
| else { | |
| if(errcode_c = fgets(usr, 20, access_token), errcode_c == NULL) return -1; | |
| if(errcode_c = fgets(id, 20, access_token), errcode_c == NULL) return -1; | |
| if(errcode_c = fgets(token, 150, access_token), errcode_c == NULL) return -1; | |
| if(errcode_c = fgets(secret, 150, access_token), errcode_c == NULL) return -1; | |
| if(errcode_c = fgets(pin, 20, access_token), errcode_c == NULL) return -1; | |
| RemoveReturn(usr, 20); | |
| RemoveReturn(id, 20); | |
| RemoveReturn(token, 150); | |
| RemoveReturn(secret, 150); | |
| RemoveReturn(pin, 20); | |
| a->user_id = usr; | |
| a->access_token = token; | |
| a->access_secret = secret; | |
| a->pin = pin; | |
| fclose(access_token); | |
| } | |
| if(errcode = Twitter_UpdateStatus(c, a, post_string), errcode < 0) { | |
| // if(errcode < -8){ | |
| return errcode; | |
| } | |
| else{ | |
| return errcode; | |
| } | |
| exit(0); | |
| } | |
| printf("Post Reply:%s\n", post_string); | |
| return 0; | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment