@@ -224,11 +224,14 @@ def patentsview_post_request(endpoint, query_param, format_param=None, options_p
224224 if not query_param :
225225 raise ValueError ("query_param is empty or None." )
226226
227- verbose = True # temp
228227 # Use urllib.parse's quote to escape JSON strings. See:
229228 # - https://stackoverflow.com/a/45758514/6288413
230229 # - https://stackoverflow.com/a/18723973/6288413
231- body = '{"q":' + re .sub ("(\r ?\n )" , " " , query_param )
230+ body = '{"q":' + re .sub ("(\r ?\n )" , " " , query_param )
231+
232+ # now for paging there needs to be sort field
233+ if sort_param is None :
234+ sort_param = '[{"' + get_default_sort_field (endpoint ) + '":"desc"}]'
232235
233236 if format_param is not None :
234237 body = body + ',"f":' + format_param
@@ -626,6 +629,21 @@ def get_options():
626629
627630 return options
628631
632+ # most of the nested endpoints use {endpoint}_id these are the exceptions
633+ use_patent_id = ["us_application_citation" , "us_patent_citation" ,
634+ "rel_app_text" , "foreign_citation" ]
635+
636+ # Now for paging there has to be a sort field. Here we'll provide defaults
637+ # for each endpoint if one isn't specied
638+ def get_default_sort_field (endpoint ):
639+
640+ # grab the last item on the url
641+ fields = endpoint .split ("/" )
642+ ending = fields [- 2 ]
643+ if ending in use_patent_id :
644+ return "patent_id"
645+ else :
646+ return ending + "_id"
629647
630648if __name__ == "__main__" :
631649 try :
0 commit comments