Advertisement
Guest User

saurik

a guest
Sep 11th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. NSDictionary *deserializeSaurikDepiction(NSString *ID) {
  2.    
  3.     NSString *depiction = [NSString stringWithFormat:@"http://cydia.saurik.com/info/%@/", ID]; /* trailing slash important /-!-\ */
  4.     NSData *depictionData = makeURLRequest(depiction);
  5.    
  6.     NSError *error;
  7.     HTMLParser *parser = [[HTMLParser alloc] initWithData:depictionData error:&error];
  8.     if (error) {
  9.         NSLog(@"Error: %@", [error localizedDescription]);
  10.         return nil;
  11.     }
  12.    
  13.     HTMLNode *head = [parser head];
  14.     HTMLNode *body = [parser body];
  15.    
  16.     NSString *name = @"", *new = @"", *description = @"", *lastUpdated = @"";
  17.     NSMutableArray *screenshots = [NSMutableArray array];
  18.    
  19.     name = [[[[head findChildTag:@"title"] allContents] componentsSeparatedByString:@" ยท "] objectAtIndex:0];
  20.    
  21.     HTMLNode *panel = [body findChildTag:@"panel"];
  22.    
  23.     description = [[[NSAttributedString alloc] initWithData:[[[[panel findChildTag:@"block"] findChildTag:@"p"] allContents] dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]} documentAttributes:nil error:nil] string];
  24.    
  25.     for (HTMLNode *img in [panel findChildTags:@"img"]) {
  26.         if (![[img getAttributeNamed:@"class"] isEqualToString:@"icon"]) {
  27.             [screenshots addObject:[img getAttributeNamed:@"src"]];
  28.         }
  29.     }
  30.    
  31.     //----------------------------//
  32.    
  33.     NSData *changelog = makeURLRequest([depiction stringByAppendingString:@"changelog.html"]);
  34.     //[parser release];
  35.    
  36.     parser = [[HTMLParser alloc] initWithData:changelog error:&error];
  37.     if (error) {
  38.         NSLog(@"Error: %@", [error localizedDescription]);
  39.     }
  40.    
  41.     body = [parser body];
  42.     panel = [body findChildTag:@"panel"];
  43.    
  44.     lastUpdated = [[[[[panel findChildTag:@"label"] findChildTag:@"p"] allContents] componentsSeparatedByString:@": "] objectAtIndex:1];
  45.     new = [[[NSAttributedString alloc] initWithData:[[panel rawContents] dataUsingEncoding:NSUTF8StringEncoding] options:@{NSDocumentTypeDocumentAttribute: NSHTMLTextDocumentType, NSCharacterEncodingDocumentAttribute: [NSNumber numberWithInt:NSUTF8StringEncoding]} documentAttributes:nil error:&error] string];
  46.    
  47.     NSMutableDictionary *dict = [NSMutableDictionary dictionary];
  48.    
  49.     [dict setObject:name forKey:@"name"];
  50.     [dict setObject:description forKey:@"description"];
  51.     [dict setObject:lastUpdated forKey:@"lastUpdated"];
  52.     [dict setObject:new forKey:@"whatsnew"];
  53.     [dict setObject:screenshots forKey:@"screenshots"];
  54.    
  55.     //[parser release];
  56.     return dict;
  57. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement