Exemplo n.º 1
0
def citation_remove_project(ref, citation_id, project_id):
    """remove project from citation
    :param ref:Firebase
    :param citation_id:str
    :param project_id:str
    """
    citation_id = str(citation_id)
    project_id = str(project_id)
    if not ref.exists('citations', citation_id):
        ref.eprint("citation #{} does'nt exist".format(citation_id))
        return
    if not ref.exists('projects', project_id):
        ref.eprint("project #{} does'nt exist".format(project_id))
        return
    data = ref.get('citations/{}'.format(citation_id))
    curr_citation = Citation.fromdict(data)
    report = curr_citation.remove_project(project_id)
    if isinstance(report, str):
        ref.eprint('could not remove project ({})'.format(report))
        return
    ref.db.child("citations/{}".format(citation_id)).set(
        curr_citation.data, ref.token)
    ref.eprint('citation #{} updated'.format(citation_id))
    # update change
    update = "citation {} removed from project {}".format(
        citation_id, project_id)
    ti = datetime.datetime.now()
    t = str(ti.day) + '-' + str(ti.month) + '-' + str(ti.year) + ' ' + str(
        ti.hour) + ':' + str(ti.minute)
    change_update(ref, t, update)
Exemplo n.º 2
0
def project_export_citations_each_style(ref,
                                        project_id,
                                        filename='export.txt'):
    """remove project from citation
    :param ref:Firebase
    :param citation_id:str
    :param project_id:str
    """
    dstyle = 'mla7'
    if not isinstance(filename, str):
        filename = 'export.txt'
    else:
        filename += '.txt' if filename[-4:] != '.txt' else ''
    project_id = str(project_id)
    if not ref.exists('projects', project_id):
        ref.eprint("project #{} does'nt exist".format(project_id))
        return
    data = ref.get('citations')
    data = filter_dict(data, 'projects', '{}:{}'.format(project_id, 'active'))
    citations = [Citation(data[item]) for item in data]
    formatted = []
    index = 0
    for cit in citations:
        formatted_cit = cit.export_easybib(
            input("enter citation #{} style: ".format(index)))
        formatted.append(formatted_cit)
        index = index + 1
    file = open(filename, 'w')
    for formatted_citation in formatted:
        json.dump(formatted_citation, file, ensure_ascii=False)
        file.write('\n')
    file.close()
    os.startfile(filename)
Exemplo n.º 3
0
def citation_remove_contributor(ref, citation_id, type):
    """remove first appearance of contributor of the same type in citation by its id
    :param ref:Firebase
    :param citation_id:str
    :param type:str
    """
    citation_id = str(citation_id)
    if not ref.exists('citations', citation_id):
        ref.eprint("citation #{} does'nt exist".format(citation_id))
        return
    data = ref.get('citations/{}'.format(citation_id))
    curr_citation = Citation.fromdict(data)
    report = curr_citation.remove_contributor(type)
    if isinstance(report, str):
        ref.eprint('could not remove contributor ({})'.format(report))
        return
    ref.db.child("citations/{}".format(citation_id)).set(
        curr_citation.data, ref.token)
    ref.eprint('removed contributor from citation #{}'.format(citation_id))
    # update change
    update = "citation {} updated".format(citation_id)
    ti = datetime.datetime.now()
    t = str(ti.day) + '-' + str(ti.month) + '-' + str(ti.year) + ' ' + str(
        ti.hour) + ':' + str(ti.minute)
    change_update(ref, t, update)
Exemplo n.º 4
0
def citation_set_type(ref, citation_id, type):
    """change citation type in database by its id
    :param ref:Firebase
    :param citation_id:str
    :param type:str
    """
    citation_id = str(citation_id)
    if not ref.exists('citations', citation_id):
        ref.eprint("citation #{} does'nt exist".format(citation_id))
        return
    data = ref.get('citations/{}'.format(citation_id))
    curr_citation = Citation.fromdict(data)
    report = curr_citation.set_type(type)
    if isinstance(report, str):
        ref.eprint('could not set publication type ({})'.format(report))
        return
    ref.db.child("citations/{}".format(citation_id)).set(
        curr_citation.data, ref.token)
    ref.eprint('changed citation #{} type to {}'.format(citation_id, type))
    # update change
    update = "citation {} updated".format(citation_id)
    ti = datetime.datetime.now()
    t = str(ti.day) + '-' + str(ti.month) + '-' + str(ti.year) + ' ' + str(
        ti.hour) + ':' + str(ti.minute)
    change_update(ref, t, update)
Exemplo n.º 5
0
def citation_add_project(ref, citation_id, project_id):
    """add project to citation
    :param ref:Firebase
    :param citation_id:str
    :param project_id:str
    """
    citation_id = str(citation_id)
    project_id = str(project_id)
    if not ref.exists('citations', citation_id):
        ref.eprint("citation #{} does'nt exist".format(citation_id))
        return
    if not ref.exists('projects', project_id):
        ref.eprint("project #{} does'nt exist".format(project_id))
        return
    if ref.exists('citations/{}/projects'.format(citation_id), project_id):
        ref.eprint("project #{} allready in citation #{}".format(
            project_id, citation_id))
        return
    data = ref.get('citations/{}'.format(citation_id))
    curr_citation = Citation.fromdict(data)
    report = curr_citation.add_project(project_id)
    if isinstance(report, str):
        ref.eprint('could not add project ({})'.format(report))
        return
    ref.db.child("citations/{}".format(citation_id)).set(
        curr_citation.data, ref.token)
    ref.eprint('citation #{} updated'.format(citation_id))
Exemplo n.º 6
0
def citation_add_contributor(ref, citation_id, type, name):
    """add contributor to citation by its id
    :param ref:Firebase
    :param citation_id:str
    :param type:str
    :param name:str
    """
    if not name_check(ref, name):
        print("contributer not available")
        return
    citation_id = str(citation_id)
    if not ref.exists('citations', citation_id):
        ref.eprint("citation #{} does'nt exist".format(citation_id))
        return
    data = ref.get('citations/{}'.format(citation_id))
    curr_citation = Citation.fromdict(data)
    report = curr_citation.add_contributor(type, name)
    if isinstance(report, str):
        ref.eprint('could not add contributor ({})'.format(report))
        return
    ref.db.child("citations/{}".format(citation_id)).set(
        curr_citation.data, ref.token)
    ref.eprint('add contributor to citation #{}'.format(citation_id))
    # update change
    update = "citation {} updated".format(citation_id)
    ti = datetime.datetime.now()
    t = str(ti.day) + '-' + str(ti.month) + '-' + str(ti.year) + ' ' + str(
        ti.hour) + ':' + str(ti.minute)
    change_update(ref, t, update)
Exemplo n.º 7
0
def citation_change_project_status(ref, citation_id, project_id,
                                   project_status):
    """change status of project in citation
    :param ref:Firebase
    :param citation_id:str
    :param project_id:str
    :param project_status:str
    """
    citation_id = str(citation_id)
    project_id = str(project_id)
    if not ref.exists('citations', citation_id):
        ref.eprint("citation #{} does'nt exist".format(citation_id))
        return
    if not ref.exists('projects', project_id):
        ref.eprint("project #{} does'nt exist".format(project_id))
        return
    data = ref.get('citations/{}'.format(citation_id))
    curr_citation = Citation.fromdict(data)
    report = curr_citation.change_project_status(project_id, project_status)
    if isinstance(report, str):
        ref.eprint('could not change project status ({})'.format(report))
        return
    ref.db.child("citations/{}".format(citation_id)).set(
        curr_citation.data, ref.token)
    ref.eprint('citation #{} updated'.format(citation_id))
Exemplo n.º 8
0
def create_citation(ref, project_id):
    """add citation to database by id
    :param ref:Firebase
    :param project_id:str
    """
    project_id = str(project_id)
    if not ref.exists("projects", project_id):
        ref.eprint("project #{} does'nt exist".format(project_id))
        return
    citation_id = ref.generate_possible_key("citations")
    curr_citation = Citation(project_id)
    ref.db.child('citations/{}'.format(citation_id)).set(
        curr_citation.data, ref.token)
    ref.eprint('citation #{} created'.format(citation_id))
Exemplo n.º 9
0
def citation_fill_data(ref, citation_id):
    """fill citation data in database by its id
    :param ref:Firebase
    :param citation_id:str
    """
    citation_id = str(citation_id)
    if not ref.exists('citations', citation_id):
        ref.eprint("citation #{} does'nt exist".format(citation_id))
        return
    data = ref.get('citations/{}'.format(citation_id))
    curr_citation = Citation.fromdict(data)
    report = curr_citation.fill_data()
    if isinstance(report, str):
        ref.eprint('could not fill citation data ({})'.format(report))
        return
    ref.db.child("citations/{}".format(citation_id)).set(
        curr_citation.data, ref.token)
    ref.eprint('citation #{} updated'.format(citation_id))
Exemplo n.º 10
0
def citation_set_type(ref, citation_id, type):
    """change citation type in database by its id
    :param ref:Firebase
    :param citation_id:str
    :param type:str
    """
    citation_id = str(citation_id)
    if not ref.exists('citations', citation_id):
        ref.eprint("citation #{} does'nt exist".format(citation_id))
        return
    data = ref.get('citations/{}'.format(citation_id))
    curr_citation = Citation.fromdict(data)
    report = curr_citation.set_type(type)
    if isinstance(report, str):
        ref.eprint('could not set publication type ({})'.format(report))
        return
    ref.db.child("citations/{}".format(citation_id)).set(
        curr_citation.data, ref.token)
    ref.eprint('changed citation #{} type to {}'.format(citation_id, type))
Exemplo n.º 11
0
def citation_remove_contributor(ref, citation_id, type):
    """remove first appearance of contributor of the same type in citation by its id
    :param ref:Firebase
    :param citation_id:str
    :param type:str
    """
    citation_id = str(citation_id)
    if not ref.exists('citations', citation_id):
        ref.eprint("citation #{} does'nt exist".format(citation_id))
        return
    data = ref.get('citations/{}'.format(citation_id))
    curr_citation = Citation.fromdict(data)
    report = curr_citation.remove_contributor(type)
    if isinstance(report, str):
        ref.eprint('could not remove contributor ({})'.format(report))
        return
    ref.db.child("citations/{}".format(citation_id)).set(
        curr_citation.data, ref.token)
    ref.eprint('removed contributor from citation #{}'.format(citation_id))
Exemplo n.º 12
0
def create_citation(ref, project_id):
    """add citation to database by id
    :param ref:Firebase
    :param project_id:str
    """
    project_id = str(project_id)
    if not ref.exists("projects", project_id):
        ref.eprint("project #{} does'nt exist".format(project_id))
        return
    citation_id = ref.generate_possible_key("citations")
    curr_citation = Citation(project_id)
    ref.db.child('citations/{}'.format(citation_id)).set(
        curr_citation.data, ref.token)
    ref.eprint('citation #{} created'.format(citation_id))
    # update change
    update = "citation {} created".format(citation_id)
    ti = datetime.datetime.now()
    t = str(ti.day) + '-' + str(ti.month) + '-' + str(ti.year) + ' ' + str(
        ti.hour) + ':' + str(ti.minute)
    change_update(ref, t, update)
Exemplo n.º 13
0
def citation_add_contributor(ref, citation_id, type, name):
    """add contributor to citation by its id
    :param ref:Firebase
    :param citation_id:str
    :param type:str
    :param name:str
    """
    citation_id = str(citation_id)
    if not ref.exists('citations', citation_id):
        ref.eprint("citation #{} does'nt exist".format(citation_id))
        return
    data = ref.get('citations/{}'.format(citation_id))
    curr_citation = Citation.fromdict(data)
    report = curr_citation.add_contributor(type, name)
    if isinstance(report, str):
        ref.eprint('could not add contributor ({})'.format(report))
        return
    ref.db.child("citations/{}".format(citation_id)).set(
        curr_citation.data, ref.token)
    ref.eprint('add contributor to citation #{}'.format(citation_id))