Yeeeeaaaaahh

![]() mailto, against spam! XML-Parser/-Writer gesuchtComputer · 19. Februar 2010 00:27 · 1 Kommentar Wer kann mir eine gute Library fuer C zum Parsen und Schreiben von XML empfehlen? Danke fuer eure Vorschlaege Amazon Preis vom N900 ueber jabber verschickenComputer · 10. Februar 2010 14:30 RTFC!
1 #!/usr/bin/perl -w 2 3 use strict; 4 5 use Net::Amazon; 6 use Net::Jabber qw(Client); 7 8 my $JABBER_ID = "btwotch-bot2"; 9 my $JABBER_PASSWD = "*****"; 10 my $JABBER_SERVER = "jabber.exados.com"; 11 my $JABBER_PORT = 5222; 12 13 my $JABBER_TO = 'btwotch@jabber.exados.com'; 14 15 my $price; 16 my $oldprice = ""; 17 18 my $ua = Net::Amazon->new( 19 token => '*****', 20 secret_key => '*****', 21 locale => 'de'); 22 23 24 my $c = Net::Jabber::Client->new(); 25 26 $c->SetCallBacks(presence => sub {}); 27 28 my $status = $c->Connect( 29 hostname => $JABBER_SERVER, 30 port => $JABBER_PORT, 31 ); 32 33 die "Can't connect: $!" unless defined $status; 34 35 my @result = $c->AuthSend( 36 username => $JABBER_ID, 37 password => $JABBER_PASSWD, 38 resource => 'n900 watcher', 39 ); 40 41 die "Can't log in: $!" unless $result[0] eq "ok"; 42 43 $c->PresenceSend(); 44 my $m = Net::Jabber::Message->new(); 45 $m->SetTo($JABBER_TO); 46 47 # Get a request object 48 while (1) 49 { 50 my $response = $ua->search(asin => 'B002N2Z0MQ'); 51 52 if($response->is_success()) { 53 $price = $response->properties()->OurPrice(); 54 $price =~ m/ (.*)/; 55 $price = $1; 56 if ($price le "600" and $price ne $oldprice) 57 { 58 $oldprice = $price; 59 $m->SetBody("aktueller Preis fuer das n900 liegt 60 bei: $price"); 61 my $rc = $c->Send($m, 1); 62 } 63 } else { 64 print "Error: ", $response->message(), "\n"; 65 } 66 67 sleep 60; 68 } Tags: amazon · jabber · n900 · xmpp Listen - man kann sie nicht oft genug programmieren ;)Sonstiges · 03. Februar 2010 02:39 · 3 Kommentare Listen - afair nicht in der libc; aber man will ja auch nicht nur wegen diesen eine extra Library einbinden, daher ist selber implementieren angesagt. Warum das ganze das Prefix 'im' hat wird erst spaeter bekanntgegeben im_list.c: 1 #include <stdlib.h> 2 3 #include "im_list.h" 4 5 6 struct node *im_list_create() 7 { 8 struct node *n; 9 10 n = malloc(sizeof(struct node)); 11 n->p = NULL; 12 n->next = NULL; 13 14 return n; 15 } 16 17 void im_list_destroy(struct node *n) 18 { 19 struct node *t; 20 while (n != NULL) 21 { 22 t = n; 23 n = n->next; 24 free(t); 25 } 26 } 27 28 29 void im_list_setp(struct node *n, void *p) 30 { 31 n->p = p; 32 } 33 34 void *im_list_getp(struct node *n) 35 { 36 return n->p; 37 } 38 39 struct node *im_list_last(struct node *n) 40 { 41 while (n->next != NULL) 42 n = n->next; 43 44 return n; 45 } 46 47 struct node *im_list_add(struct node *n) 48 { 49 struct node *o; 50 struct node *new; 51 52 new = im_list_create(); 53 54 o = n->next; 55 n->next = new; 56 new->next = o; 57 58 return new; 59 } 60 61 void im_list_delnext(struct node *n) 62 { 63 struct node *next; 64 65 next = n->next; 66 67 n->next = (n->next->next != NULL) ? n->next->next : NULL; 68 69 free(next); 70 } 71 72 void im_list_walkthrough(struct node *n, void (*fp)(void*, void*), void *ud) 73 { 74 while (n != NULL) 75 { 76 if (im_list_getp(n) != NULL) 77 fp(im_list_getp(n), ud); 78 n = n->next; 79 } 80 } im_list.h 1 struct node *im_list_create(); 2 void im_list_destroy(struct node *n); 3 void im_list_setp(struct node*, void*); 4 void *im_list_getp(struct node*); 5 struct node *im_list_last(struct node*); 6 struct node *im_list_add(struct node*); 7 void im_list_delnext(struct node *n); 8 void im_list_walkthrough(struct node*, void (*fp)(void*, void*), void*); 9 10 struct node 11 { 12 struct node *next; 13 void *p; 14 }; listtest.c 1 #include <stdio.h> 2 3 #include "im_list.h" 4 5 void wt(void *p, void *ud) 6 { 7 printf("- %s\n", (char*)p); 8 } 9 10 11 int main() 12 { 13 struct node *n; 14 15 n = im_list_create(); 16 17 im_list_setp(n, "Das"); 18 im_list_setp(im_list_add(n), "das"); 19 im_list_setp(im_list_add(n), "ist"); 20 21 im_list_walkthrough(n, wt, NULL); 22 23 im_list_delnext(n); 24 im_list_walkthrough(n, wt, NULL); 25 26 im_list_destroy(n); 27 } |
Einträge anzeigen
Jahr 2012 (3) AbonnierenTags |