h-booru-0.3.0.0: Haskell library for retrieving data from various booru image sites

Copyright(c) Mateusz Kowalczyk 2014
LicenseGPL-3
Maintainerfuuzetsu@fuuzetsu.co.uk
Stabilityexperimental
Safe HaskellNone
LanguageHaskell2010
Extensions
  • MonoLocalBinds
  • GADTs
  • GADTSyntax
  • ConstraintKinds
  • DataKinds
  • DeriveDataTypeable
  • FlexibleContexts
  • UnicodeSyntax
  • TypeOperators
  • ExplicitNamespaces

HBooru.Parsers.FieldParsers

Contents

Description

A collection of arrow parsers for known fields. We can use these (and write new ones) by composing these parsers together for each site we want to parse. As we carry the field information with us, this can later be used when trying to extract the parsed information from the sites into a homogenous list. Currently this moduel only deals with parsing out XML attributes.

Synopsis

Documentation

newtype E Source

Constructors

E String 

Instances

type ParseArrow cat = (Functor (cat XmlTree), ArrowXml cat) Source

Alias for the common constraint blob

type Field cat s = cat XmlTree (Parse (R `[s]`)) Source

Alias for named fields

readAttr :: (ArrowXml cat, Read (App ElF s), Functor (cat XmlTree)) => String -> sing s -> Field cat s Source

Helper that provides better error messages when a read fails.

readAttrWith :: (ArrowXml cat, Functor (cat XmlTree)) => String -> sing s -> (String -> Maybe (App ElF s)) -> Field cat s Source

readCustom :: (ArrowXml cat, Functor (cat XmlTree)) => String -> sing s -> (String -> Parse (App ElF s)) -> Field cat s Source

readNormalAttr :: (ArrowXml cat, App ElF s ~ String, Functor (cat XmlTree)) => String -> sing s -> Field cat s Source

Individual attribute parsers

heightA :: ParseArrow cat => Field cat "height" Source

Parser arrow for a "height" XML attribute.

scoreA :: ParseArrow cat => Field cat "score" Source

Parser arrow for a "score" XML attribute.

file_urlA :: ParseArrow cat => Field cat "file_url" Source

Parser arrow for a "file_url" XML attribute.

parent_idA :: ParseArrow cat => Field cat "parent_id" Source

Parser arrow for a "parent_id" XML attribute.

sample_urlA :: ParseArrow cat => Field cat "sample_url" Source

Parser arrow for a "sample_url" XML attribute.

sample_widthA :: ParseArrow cat => Field cat "sample_width" Source

Parser arrow for a "sample_width" XML attribute.

sample_heightA :: ParseArrow cat => Field cat "sample_height" Source

Parser arrow for a "sample_height" XML attribute.

preview_urlA :: ParseArrow cat => Field cat "preview_url" Source

Parser arrow for a "preview_url" XML attribute.

ratingA :: ParseArrow cat => Field cat "rating" Source

Parser arrow for a "rating" XML attribute.

tagsA :: ParseArrow cat => Field cat "tags" Source

Parser arrow for a "tags" XML attribute.

idA :: ParseArrow cat => Field cat "id" Source

Parser arrow for a "id" XML attribute.

widthA :: ParseArrow cat => Field cat "width" Source

Parser arrow for a "width" XML attribute.

changeA :: ParseArrow cat => Field cat "change" Source

Parser arrow for a "change" XML attribute.

md5A :: ParseArrow cat => Field cat "md5" Source

Parser arrow for a "md5" XML attribute.

creator_idA :: ParseArrow cat => Field cat "creator_id" Source

Parser arrow for a "creator_id" XML attribute.

has_childrenA :: ParseArrow cat => Field cat "has_children" Source

Parser arrow for a "has_children" XML attribute.

created_atA :: ParseArrow cat => Field cat "created_at" Source

Parser arrow for a "created_at" XML attribute.

statusA :: ParseArrow cat => Field cat "status" Source

Parser arrow for a "status" XML attribute.

sourceA :: ParseArrow cat => Field cat "source" Source

Parser arrow for a "source" XML attribute.

has_notesA :: ParseArrow cat => Field cat "has_notes" Source

Parser arrow for a "has_notes" XML attribute.

has_commentsA :: ParseArrow cat => Field cat "has_comments" Source

Parser arrow for a "has_comments" XML attribute.

preview_widthA :: ParseArrow cat => Field cat "preview_width" Source

Parser arrow for a "preview_width" XML attribute.

preview_heightA :: ParseArrow cat => Field cat "preview_height" Source

Parser arrow for a "preview_height" XML attribute.

authorA :: ParseArrow cat => Field cat "author" Source

Parser arrow for a "author" XML attribute.

actual_preview_heightA :: ParseArrow cat => Field cat "actual_preview_height" Source

Parser arrow for a "actual_preview_height" XML attribute.

actual_preview_widthA :: ParseArrow cat => Field cat "actual_preview_width" Source

Parser arrow for a "actual_preview_width" XML attribute.

framesA :: ParseArrow cat => Field cat "frames" Source

Parser arrow for a "frames" XML attribute.

frames_pendingA :: ParseArrow cat => Field cat "frames_pending" Source

Parser arrow for a "frames_pending" XML attribute.

frames_pending_stringA :: ParseArrow cat => Field cat "frames_pending_string" Source

Parser arrow for a "frames_pending_string" XML attribute.

frames_stringA :: ParseArrow cat => Field cat "frames_string" Source

Parser arrow for a "frames_string" XML attribute.

is_heldA :: ParseArrow cat => Field cat "is_held" Source

Parser arrow for a "is_held" XML attribute.

is_shown_in_indexA :: ParseArrow cat => Field cat "is_shown_in_index" Source

Parser arrow for a "is_shown_in_index" XML attribute.

jpeg_file_sizeA :: ParseArrow cat => Field cat "jpeg_file_size" Source

Parser arrow for a "jpeg_file_size" XML attribute.

jpeg_heightA :: ParseArrow cat => Field cat "jpeg_height" Source

Parser arrow for a "jpeg_height" XML attribute.

jpeg_urlA :: ParseArrow cat => Field cat "jpeg_url" Source

Parser arrow for a "jpeg_url" XML attribute.

jpeg_widthA :: ParseArrow cat => Field cat "jpeg_width" Source

Parser arrow for a "jpeg_width" XML attribute.

sample_file_sizeA :: ParseArrow cat => Field cat "sample_file_size" Source

Parser arrow for a "sample_file_size" XML attribute.

file_sizeA :: ParseArrow cat => Field cat "file_size" Source

Parser arrow for a "file_size" XML attribute.

Parsing helpers

parseRating :: String -> Maybe Rating Source

Parses a string returned from a Gelbooru-like site into one of the commonly used Ratings. Note that this is a partial function so you should make sure that the site in question only ever returns the values in a format specified in the function

parseTags :: String -> [Tag] Source

Splits returned tag string into separate Tags. For Gelbooru-like sites, this is just the question of splitting on whitespace.

parseBool :: String -> Maybe Bool Source

Reads a lowercase Bool string representation into its Haskell type. If we can't parse the boolean, return Nothing.

(<:+>) :: Arrow cat => cat b (Parse (R as)) -> cat b (Parse (R bs)) -> cat b (Parse (R (as ++ bs))) infixr 5 Source

A little helper that lifts <+> into Arrow which allows us to compose parsers returning records very easily.