using JSON, BibTeX # Downloading using URIParser, HTTP #= Mapping between zotero and BibTeX. =# # https://github.com/retorquere/zotero-better-bibtex/blob/master/translators/Better%20BibLaTeX.ts "Map zotero reference types to bibtex" const zotero_type_map = Dict( "artwork" => "artwork", "audioRecording" => "audio", "bill" => "legislation", "blogPost" => "online", "book" => "book", "bookSection" => "incollection", "case" => "jurisdiction", "computerProgram" => "software", "conferencePaper" => "inproceedings", "dictionaryEntry" => "inreference", "document" => "misc", "email" => "letter", "encyclopediaArticle" => "misc", # "inreference", "film" => "movie", "forumPost" => "online", "hearing" => "jurisdiction", "instantMessage" => "misc", "interview" => "misc", "journalArticle" => "article", "letter" => "letter", "magazineArticle" => "article", "manuscript" => "unpublished", "map" => "misc", "newspaperArticle" => "article", "patent" => "patent", "podcast" => "audio", "presentation" => "unpublished", "radioBroadcast" => "audio", "report" => "report", "statute" => "legislation", "thesis" => "thesis", "tvBroadcast" => "video", "videoRecording" => "video", "webpage" => "online" ) # , subtype: "magazine"}, # , subtype: "newspaper"}, "Map zotero fields to bibtex fields" const zotero_field_map = Dict( "title" => "title", "pages" => "pages", "DOI" => "DOI", "ISSN" => "ISSN", "publisher" => "publisher", "publicationTitle" => "journal", "date" => "year", "volume" => "volume", "issue" => "number" # FIXME: ADD TAGS? ) "Parses the `creatorType` field and creates a string with authors" function creatortoauthor(c::Dict) ctype = c["creatorType"] if ctype != "author" error("Add this creator type($(ctype)) to the supported ones!") end """{$(c["lastName"]), $(c["firstName"])}""" end "Takes all zotero creators, converts and join them" authors(c) = join(creatortoauthor.(c), " and ") #= Functions used to interface with the zotero connector =# """Creates the response by using the response body `res`, the default `headers` and the headers to add (`extraheaders`). Defines the hook `set_headers` (before setting them) and `post_headers_merge` (before sending the response) """ function setzoteroheaders(res, extraheaders::Dict) @hook :set_headers newheaders = merge(headers, extraheaders) @hook :post_headers_merge (newheaders,) Dict(:headers => newheaders, :body => res) end """ The zotero connector sometimes pings the program to see if we are listening (e.g., before sending the data). This must support both GET and POST. Defines the hook `ping` """ function pong(app) @hook :ping if app[:method] == "POST" headers = Dict("Content-Type" => "application/json") # FIXME: get(libraries[currentlibrary],"autosnapshot", false) response = json(Dict("prefs" => Dict("automaticSnapshots" => false ))) else headers = Dict("Content-Type" => "text/html") response = """