예제 #1
0
        else:
            sql += "'unknown'"
        sql += ');\n'
        if (sql != "insert into articles(year,venue,title) values(1900, 'unknown', 'unknown');\n") and ('\\' not in sql):
            return sql
        else:
            return ""

print "opening file..."
with open("InsertingData/dblp1.xml", buffering=200000) as input:
    output = open("dump.data", "w")
    for line in input:
        article = get_data(line)
        if article.__str__():
            if article.author:
                author = Authors().get(name=article.author)
                if author:
                    article.author_id = author.id
                else:
                    author = Authors()
                    author.name = article.author[1:][:-1]
                    author.save()
                    author = Authors().get(name=author.name)[0]
                    article.author = [author.id, ]
                    output.write(article.__str__())
                    for i in article.author:
                        sql = '''
                        insert into authorlists(author_id,article_id) values
                        ({author},{article});
                        '''.format(author=i, article=ArticleModel().get(title=article.title))