Skip to content

Commit

Permalink
add as_json() method
Browse files Browse the repository at this point in the history
  • Loading branch information
Tommos0 authored Mar 26, 2018
1 parent 4390ea3 commit b750559
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion cff_converter_python/citation.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
import requests
import yaml
import re
import json
from datetime import datetime, date

class JSONEncoder(json.JSONEncoder):
def default(self, o):
if isinstance(o, (datetime, date)):
return o.isoformat()
return o.__dict__

class Citation:

Expand Down Expand Up @@ -53,7 +60,10 @@ def _parse_yaml(self):
self.as_yaml = yaml.safe_load(self.file_contents)
if not isinstance(self.as_yaml, dict):
raise Exception("Provided CITATION.cff does not seem valid YAML.")


def as_json(self):
return JSONEncoder().encode(self.as_yaml)

def as_bibtex(self):

def get_author_string():
Expand Down

0 comments on commit b750559

Please sign in to comment.