CrunchBang Linux Pastebin - collaborative debugging

pastebin is a collaborative debugging tool allowing you to share and modify code snippets while chatting on IRC, IM or a message board.

This site is developed to XHTML and CSS2 W3C standards. If you see this paragraph, your browser does not support those standards and you need to upgrade. Visit WaSP for a variety of options.

CrunchBang Linux Pastebin

Posted by TeoBigusGeekus on Tue 29th May 21:23 (modification of post by view diff)
download | new post

  1. #include <curl/curl.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <sys/stat.h>
  5. #include <stdlib.h>
  6. #include <stdbool.h>
  7.  
  8. char *test_image_day(char *input,char *output);
  9. char *test_image_night(char *input,char *output);
  10.  
  11. int main(void)
  12. {
  13. /* Pause conky if open */
  14.  
  15.     FILE *pid=popen("kill -STOP $(pidof conky)","r");
  16.     pclose(pid);
  17.  
  18.    
  19.     char acc_addr[120]="http://www.accuweather.com/en/gr/kastoria/178682/weather-forecast/178682";
  20.  
  21.     char *last_number;
  22.     last_number=strstr(acc_addr,"weather-forecast/")+17;
  23.     char temp[120]="";
  24.     *(strstr(acc_addr,"weather-forecast"))='\0';
  25.     strcpy(temp,acc_addr);
  26.  
  27.     char curr_addr[120];
  28.     strcpy(curr_addr,temp);
  29.     strcat(curr_addr,"current-weather/");
  30.     strcat(curr_addr,last_number);
  31.  
  32.     char addr1[120];
  33.     strcpy(addr1,temp);
  34.     strcat(addr1,"daily-weather-forecast/");
  35.     strcat(addr1,last_number);
  36.  
  37.     char addr2[120];
  38.     strcpy(addr2,addr1);
  39.     strcat(addr2,"?day=6");
  40.  
  41.     CURL* easyhandle = curl_easy_init();
  42.    
  43.     curl_easy_setopt( easyhandle, CURLOPT_URL, curr_addr ) ;
  44.     FILE* file_curr = fopen( "/home/teo/accuweather_conky_modified/curr_cond", "w");
  45.     curl_easy_setopt( easyhandle, CURLOPT_WRITEDATA, file_curr) ;
  46.     curl_easy_perform( easyhandle );
  47.     fclose(file_curr);
  48.  
  49.     curl_easy_setopt( easyhandle, CURLOPT_URL, addr1) ;
  50.     FILE* file_tod_ton = fopen( "/home/teo/accuweather_conky_modified/tod_ton", "w");
  51.     curl_easy_setopt( easyhandle, CURLOPT_WRITEDATA, file_tod_ton) ;
  52.     curl_easy_perform( easyhandle );
  53.     fclose(file_tod_ton);
  54.  
  55.     curl_easy_setopt( easyhandle, CURLOPT_URL, addr2) ;
  56.     FILE* file_last_days = fopen( "/home/teo/accuweather_conky_modified/last_days", "w");
  57.     curl_easy_setopt( easyhandle, CURLOPT_WRITEDATA, file_last_days) ;
  58.     curl_easy_perform( easyhandle );
  59.     fclose(file_last_days);
  60.  
  61.     curl_easy_cleanup( easyhandle );
  62.  
  63.  
  64. /******************
  65. * FILE: curr_cond *
  66. *******************/
  67.  
  68.     struct stat st;
  69.     stat("/home/teo/accuweather_conky_modified/curr_cond",&st);
  70.     int size=st.st_size;
  71.  
  72.     file_curr = fopen( "/home/teo/accuweather_conky_modified/curr_cond", "r");
  73.     char *arr_cc=malloc(size+1);
  74.     fread(arr_cc,1,size,file_curr);
  75.     fclose(file_curr);
  76.  
  77.     memmove(arr_cc,strstr(arr_cc,"#detail-now"),strlen(strstr(arr_cc,"#detail-now")));
  78.     *(strstr(arr_cc,"#details"))='\0';
  79.  
  80.     file_curr = fopen( "/home/teo/accuweather_conky_modified/curr_cond", "w");
  81.  
  82.     bool day=true;
  83.     int i=0,j,k;
  84.     char tmp[502]="",buff[2]="";
  85.     while (arr_cc[i] != '\0') {
  86.        j=0;
  87.        while (arr_cc[i] != '\n' && arr_cc[i] != '\0' && arr_cc[i] != '\r' && j <= 500)
  88.            tmp[j++]=arr_cc[i++];
  89.  
  90.         tmp[j]='\n';
  91.         tmp[++j]='\0';
  92.  
  93.        if (arr_cc[i] != '\0')
  94.            i++;
  95.  
  96.        if (strstr(tmp,"\"detail-tab-panel ")) {
  97.            memmove(tmp,strstr(tmp,"\"detail-tab-panel ")+18,strlen(strstr(tmp,"\"detail-tab-panel ")+18));
  98.            *(strstr(tmp,"\">"))='\n';
  99.            *(strstr(tmp,">"))='\0';
  100.            if (strstr(tmp,"night"))
  101.                day=false;
  102.            else if (strstr(tmp,"day"))
  103.                day=true;
  104.            fwrite(tmp,1,strlen(tmp),file_curr);
  105.        } else if (strstr(tmp,"icon i-")) {
  106.            memmove(tmp,strstr(tmp,"icon i-")+7,strlen(strstr(tmp,"icon i-")+7));
  107.            *(strstr(tmp,"\">"))='\0';
  108.            if (day)
  109.                test_image_day(tmp,buff);
  110.            else
  111.                test_image_night(tmp,buff);
  112.            fwrite(buff,1,strlen(buff),file_curr);
  113.            fprintf(file_curr,"\n");
  114.        } else if (strstr(tmp,"cond\">")) {
  115.            memmove(tmp,strstr(tmp,"cond\">")+6,strlen(strstr(tmp,"cond\">")+6));
  116.            *(strstr(tmp,"</span>"))='\n';
  117.            k=0;
  118.            while (tmp[k]!='\n')
  119.                fprintf(file_curr,"%c",tmp[k++]);
  120.            fprintf(file_curr,"\n");
  121.            memmove(tmp,strstr(tmp,"/span> <span class=\"temp\">")+26,strlen(strstr(tmp,"/span> <span class=\"temp\">")+26));
  122.            *(strstr(tmp,"<span>"))='\n';
  123.            *(strstr(tmp,"span>"))='\0';
  124.            fwrite(tmp,1,strlen(tmp),file_curr);
  125.        }
  126.     }
  127.    
  128.     free(arr_cc);
  129.     fclose(file_curr);
  130.  
  131.    
  132. /****************
  133. * FILE: tod_ton *
  134. *****************/
  135.  
  136.     stat("/home/teo/accuweather_conky_modified/tod_ton",&st);
  137.     size=st.st_size;
  138.  
  139.     file_tod_ton = fopen( "/home/teo/accuweather_conky_modified/tod_ton", "r");
  140.     char *arr_tt=malloc(size+1);
  141.     fread(arr_tt,1,size,file_tod_ton);
  142.     fclose(file_tod_ton);
  143.  
  144.     memmove(arr_tt,strstr(arr_tt,"\"feed-tabs"),strlen(strstr(arr_tt,"\"feed-tabs")));
  145.     *(strstr(arr_tt,".feed-tabs"))='\0';
  146.  
  147.     file_tod_ton = fopen( "/home/teo/accuweather_conky_modified/tod_ton", "w");
  148.  
  149.     i=0;
  150.     bool night=false;
  151.     strcpy(tmp,"");
  152.     strcpy(buff,"");
  153.     while (arr_tt[i] != '\0') {
  154.        j=0;
  155.        while (arr_tt[i] != '\n' && arr_tt[i] != '\0' && arr_tt[i] != '\r' && j <= 500)
  156.            tmp[j++]=arr_tt[i++];
  157.  
  158.         tmp[j]='\n';
  159.         tmp[++j]='\0';
  160.  
  161.        if (arr_tt[i] != '\0')
  162.            i++;
  163.  
  164.        if (strstr(tmp,"href=\"#\">")) {
  165.            memmove(tmp,strstr(tmp,"href=\"#\">")+9,strlen(strstr(tmp,"href=\"#\">")+9));
  166.            *(strstr(tmp,"</a>"))='\n';
  167.            *(strstr(tmp,"/a>"))='\0';
  168.            if (strstr(tmp,"Tonight") || strstr(tmp,"Early AM"))
  169.                night=true;
  170.            else
  171.                night=false;
  172.            if (strstr(tmp,"Early AM"))
  173.                    fwrite("AM\n",1,strlen("AM\n"),file_tod_ton);
  174.            else if (strstr(tmp,"Today"))
  175.                    fwrite("TOD\n",1,strlen("TOD\n"),file_tod_ton);
  176.            else if (strstr(tmp,"Tonight"))
  177.                    fwrite("TON\n",1,strlen("TON\n"),file_tod_ton);
  178.            else if (strstr(tmp,"Mon"))
  179.                    fwrite("MON\n",1,strlen("MON\n"),file_tod_ton);
  180.            else if (strstr(tmp,"Tue"))
  181.                    fwrite("TUE\n",1,strlen("TUE\n"),file_tod_ton);
  182.            else if (strstr(tmp,"Wed"))
  183.                    fwrite("WED\n",1,strlen("WED\n"),file_tod_ton);
  184.            else if (strstr(tmp,"Thu"))
  185.                    fwrite("THU\n",1,strlen("THU\n"),file_tod_ton);
  186.            else if (strstr(tmp,"Fri"))
  187.                    fwrite("FRI\n",1,strlen("FRI\n"),file_tod_ton);
  188.            else if (strstr(tmp,"Sat"))
  189.                    fwrite("SAT\n",1,strlen("SAT\n"),file_tod_ton);
  190.            else if (strstr(tmp,"Sun"))
  191.                    fwrite("SUN\n",1,strlen("SUN\n"),file_tod_ton);
  192.        } else if (strstr(tmp,"icon i-")) {
  193.            memmove(tmp,strstr(tmp,"icon i-")+7,strlen(strstr(tmp,"icon i-")+7));
  194.            if (strstr(tmp,"i-alarm"))
  195.                *(strstr(tmp," i-alarm"))='\0';
  196.            else
  197.                *(strstr(tmp," \"></div>"))='\0';
  198.            if (!night)
  199.                test_image_day(tmp,buff);
  200.            else
  201.                test_image_night(tmp,buff);
  202.            fwrite(buff,1,strlen(buff),file_tod_ton);
  203.            fprintf(file_tod_ton,"\n");
  204.        } else if (strstr(tmp,"cond\">")) {
  205.            memmove(tmp,strstr(tmp,"cond\">")+6,strlen(strstr(tmp,"cond\">")+6));
  206.            *(strstr(tmp,"</span>"))='\n';
  207.            *(strstr(tmp,"/span>"))='\0';
  208.            fwrite(tmp,1,strlen(tmp),file_tod_ton);
  209.        } else if (strstr(tmp,"temp\">")) {
  210.            memmove(tmp,strstr(tmp,"temp\">")+6,strlen(strstr(tmp,"temp\">")+6));
  211.            *(strstr(tmp,"<span>&deg"))='\n';
  212.            if (night) {
  213.                *(strstr(tmp,"span>&deg"))='\0';
  214.                fprintf(file_tod_ton,"-\n");
  215.                fwrite(tmp,1,strlen(tmp),file_tod_ton);
  216.            } else {
  217.                k=0;
  218.                while (tmp[k]!='\n')
  219.                    fprintf(file_tod_ton,"%c",tmp[k++]);
  220.                fprintf(file_tod_ton,"\n");
  221.                memmove(tmp,strstr(tmp,"Lo</span> ")+10,strlen(strstr(tmp,"Lo</span> ")+10));
  222.                *(strstr(tmp,"<span>&deg"))='\n';
  223.                *(strstr(tmp,"span>&deg"))='\0';
  224.                fwrite(tmp,1,strlen(tmp),file_tod_ton);
  225.            }
  226.        }
  227.     }
  228.  
  229.     free(arr_tt);
  230.     fclose(file_tod_ton);
  231.  
  232.  
  233. /*****************
  234. * FILE: last_days*
  235. ******************/
  236.  
  237.     stat("/home/teo/accuweather_conky_modified/last_days",&st);
  238.     size=st.st_size;
  239.  
  240.     file_last_days= fopen( "/home/teo/accuweather_conky_modified/last_days", "r");
  241.     char *arr_ld=malloc(size+1);
  242.     fread(arr_ld,1,size,file_last_days);
  243.     fclose(file_last_days);
  244.  
  245.     memmove(arr_ld,strstr(arr_ld,"\"feed-tabs"),strlen(strstr(arr_ld,"\"feed-tabs")));
  246.     *(strstr(arr_ld,".feed-tabs"))='\0';
  247.  
  248.     file_last_days = fopen( "/home/teo/accuweather_conky_modified/last_days", "w");
  249.  
  250.     i=0;
  251.     strcpy(tmp,"");
  252.     strcpy(buff,"");
  253.     while (arr_ld[i] != '\0') {
  254.        j=0;
  255.        while (arr_ld[i] != '\n' && arr_ld[i] != '\0' && arr_ld[i] != '\r' && j <= 500)
  256.            tmp[j++]=arr_ld[i++];
  257.  
  258.         tmp[j]='\n';
  259.         tmp[++j]='\0';
  260.  
  261.        if (arr_ld[i] != '\0')
  262.            i++;
  263.        
  264.        if (strstr(tmp,"href=\"#\">")) {
  265.            memmove(tmp,strstr(tmp,"href=\"#\">")+9,strlen(strstr(tmp,"href=\"#\">")+9));
  266.            *(strstr(tmp,"</a>"))='\n';
  267.            *(strstr(tmp,"/a>"))='\0';
  268.            if (strstr(tmp,"Mon"))
  269.                    fwrite("MON\n",1,strlen("MON\n"),file_last_days);
  270.            else if (strstr(tmp,"Tue"))
  271.                    fwrite("TUE\n",1,strlen("TUE\n"),file_last_days);
  272.            else if (strstr(tmp,"Wed"))
  273.                    fwrite("WED\n",1,strlen("WED\n"),file_last_days);
  274.            else if (strstr(tmp,"Thu"))
  275.                    fwrite("THU\n",1,strlen("THU\n"),file_last_days);
  276.            else if (strstr(tmp,"Fri"))
  277.                    fwrite("FRI\n",1,strlen("FRI\n"),file_last_days);
  278.            else if (strstr(tmp,"Sat"))
  279.                    fwrite("SAT\n",1,strlen("SAT\n"),file_last_days);
  280.            else if (strstr(tmp,"Sun"))
  281.                    fwrite("SUN\n",1,strlen("SUN\n"),file_last_days);
  282.        } else if (strstr(tmp,"icon i-")) {
  283.            memmove(tmp,strstr(tmp,"icon i-")+7,strlen(strstr(tmp,"icon i-")+7));
  284.            if (strstr(tmp,"i-alarm"))
  285.                *(strstr(tmp," i-alarm"))='\0';
  286.            else
  287.                *(strstr(tmp," \"></div>"))='\0';
  288.            test_image_day(tmp,buff);
  289.            fwrite(buff,1,strlen(buff),file_last_days);
  290.            fprintf(file_last_days,"\n");
  291.        } else if (strstr(tmp,"cond\">")) {
  292.            memmove(tmp,strstr(tmp,"cond\">")+6,strlen(strstr(tmp,"cond\">")+6));
  293.            *(strstr(tmp,"</span>"))='\n';
  294.            *(strstr(tmp,"/span>"))='\0';
  295.            fwrite(tmp,1,strlen(tmp),file_last_days);
  296.        } else if (strstr(tmp,"temp\">")) {
  297.            memmove(tmp,strstr(tmp,"temp\">")+6,strlen(strstr(tmp,"temp\">")+6));
  298.            *(strstr(tmp,"<span>&deg"))='\n';
  299.            k=0;
  300.            while (tmp[k]!='\n')
  301.                fprintf(file_last_days,"%c",tmp[k++]);
  302.            fprintf(file_last_days,"\n");
  303.            memmove(tmp,strstr(tmp,"Lo</span> ")+10,strlen(strstr(tmp,"Lo</span> ")+10));
  304.            *(strstr(tmp,"<span>&deg"))='\n';
  305.            *(strstr(tmp,"span>&deg"))='\0';
  306.            fwrite(tmp,1,strlen(tmp),file_last_days);
  307.        }
  308.     }
  309.  
  310.     free(arr_ld);
  311.     fclose(file_last_days);
  312.  
  313.  
  314. /* Resume conky if paused */
  315.    
  316.     pid=popen("kill -CONT $(pidof conky)","r");
  317.     pclose(pid);
  318.  
  319.     return 0;
  320. }
  321.  
  322. char *test_image_day(char *input,char *output)
  323. {
  324.     if (strcmp(input,"su") == 0)
  325.         strcpy(output,"a");
  326.     else if (strcmp(input,"msu") == 0)
  327.         strcpy(output,"b ");
  328.     else if (strcmp(input,"psu") == 0)
  329.         strcpy(output,"c");
  330.     else if (strcmp(input,"ic") == 0)
  331.         strcpy(output,"c");
  332.     else if (strcmp(input,"h") == 0)
  333.         strcpy(output,"c");
  334.     else if (strcmp(input,"mc") == 0)
  335.         strcpy(output,"d");
  336.     else if (strcmp(input,"c") == 0)
  337.         strcpy(output,"e");
  338.     else if (strcmp(input,"d") == 0)
  339.         strcpy(output,"e");
  340.     else if (strcmp(input,"f") == 0)
  341.         strcpy(output,"0");
  342.     else if (strcmp(input,"s") == 0)
  343.         strcpy(output,"h");
  344.     else if (strcmp(input,"mcs") == 0)
  345.         strcpy(output,"g");
  346.     else if (strcmp(input,"psus") == 0)
  347.         strcpy(output,"g");
  348.     else if (strcmp(input,"t") == 0)
  349.         strcpy(output,"l");
  350.     else if (strcmp(input,"mct") == 0)
  351.         strcpy(output,"k");
  352.     else if (strcmp(input,"psut") == 0)
  353.         strcpy(output,"k");
  354.     else if (strcmp(input,"r") == 0)
  355.         strcpy(output,"i");
  356.     else if (strcmp(input,"fl") == 0)
  357.         strcpy(output,"p");
  358.     else if (strcmp(input,"mcfl") == 0)
  359.         strcpy(output,"o");
  360.     else if (strcmp(input,"psfl") == 0)
  361.         strcpy(output,"o");
  362.     else if (strcmp(input,"sn") == 0)
  363.         strcpy(output,"r");
  364.     else if (strcmp(input,"mcsn") == 0)
  365.         strcpy(output,"o");
  366.     else if (strcmp(input,"i") == 0)
  367.         strcpy(output,"E");
  368.     else if (strcmp(input,"sl") == 0)
  369.         strcpy(output,"u");
  370.     else if (strcmp(input,"fr") == 0)
  371.         strcpy(output,"i");
  372.     else if (strcmp(input,"rsn") == 0)
  373.         strcpy(output,"v");
  374.     else if (strcmp(input,"w") == 0)
  375.         strcpy(output,"6");
  376.     else if (strcmp(input,"ho") == 0)
  377.         strcpy(output,"5");
  378.     else if (strcmp(input,"co") == 0)
  379.         strcpy(output,"E");
  380.     else if (strcmp(input,"cl") == 0)
  381.         strcpy(output,"A");
  382.     else if (strcmp(input,"mcl") == 0)
  383.         strcpy(output,"B");
  384.     else if (strcmp(input,"pc") == 0)
  385.         strcpy(output,"C");
  386.     else if (strcmp(input,"pcs") == 0)
  387.         strcpy(output,"G");
  388.     else if (strcmp(input,"pct") == 0)
  389.         strcpy(output,"K");
  390.     else
  391.         strcpy(output,"\0");
  392.  
  393.     return output;
  394. }
  395.  
  396. char *test_image_night(char *input,char *output)
  397. {
  398.  
  399.     if (strcmp(input,"su") == 0)
  400.         strcpy(output,"a");
  401.     else if (strcmp(input,"msu") == 0)
  402.         strcpy(output,"b");
  403.     else if (strcmp(input,"psu") == 0)
  404.         strcpy(output,"c");
  405.     else if (strcmp(input,"c") == 0)
  406.         strcpy(output,"f");
  407.     else if (strcmp(input,"d") == 0)
  408.         strcpy(output,"f");
  409.     else if (strcmp(input,"f") == 0)
  410.         strcpy(output,"f");
  411.     else if (strcmp(input,"s") == 0)
  412.         strcpy(output,"h");
  413.     else if (strcmp(input,"psus") == 0)
  414.         strcpy(output,"g");
  415.     else if (strcmp(input,"t") == 0)
  416.         strcpy(output,"l");
  417.     else if (strcmp(input,"psut") == 0)
  418.         strcpy(output,"k");
  419.     else if (strcmp(input,"r") == 0)
  420.         strcpy(output,"i");
  421.     else if (strcmp(input,"fl") == 0)
  422.         strcpy(output,"p");
  423.     else if (strcmp(input,"psfl") == 0)
  424.         strcpy(output,"o");
  425.     else if (strcmp(input,"sn") == 0)
  426.         strcpy(output,"r");
  427.     else if (strcmp(input,"i") == 0)
  428.         strcpy(output,"E");
  429.     else if (strcmp(input,"sl") == 0)
  430.         strcpy(output,"u");
  431.     else if (strcmp(input,"fr") == 0)
  432.         strcpy(output,"i");
  433.     else if (strcmp(input,"rsn") == 0)
  434.         strcpy(output,"v");
  435.     else if (strcmp(input,"ho") == 0)
  436.         strcpy(output,"5");
  437.     else if (strcmp(input,"co") == 0)
  438.         strcpy(output,"E");
  439.     else if (strcmp(input,"cl") == 0)
  440.         strcpy(output,"A");
  441.     else if (strcmp(input,"w") == 0)
  442.         strcpy(output,"6");
  443.     else if (strcmp(input,"mcl") == 0)
  444.         strcpy(output,"B");
  445.     else if (strcmp(input,"pc") == 0)
  446.         strcpy(output,"C");
  447.     else if (strcmp(input,"ic") == 0)
  448.         strcpy(output,"B");
  449.     else if (strcmp(input,"h") == 0)
  450.         strcpy(output,"B");
  451.     else if (strcmp(input,"mc") == 0)
  452.         strcpy(output,"C");
  453.     else if (strcmp(input,"pcs") == 0)
  454.         strcpy(output,"G");
  455.     else if (strcmp(input,"mcs") == 0)
  456.         strcpy(output,"G");
  457.     else if (strcmp(input,"pct") == 0)
  458.         strcpy(output,"K");
  459.     else if (strcmp(input,"mct") == 0)
  460.         strcpy(output,"K");
  461.     else if (strcmp(input,"mcfl") == 0)
  462.         strcpy(output,"O");
  463.     else if (strcmp(input,"mcsn") == 0)
  464.         strcpy(output,"O");
  465.     else
  466.         strcpy(output,"\0");
  467.  
  468.     return output;
  469. }

Submit a correction or amendment below (click here to make a fresh posting)
After submitting an amendment, you'll be able to view the differences between the old and new posts easily.

Syntax highlighting:

To highlight particular lines, prefix each line with @@


Remember me