Arthur Camberlein >> SEO & Data articles >> Diff date usage in Python

Diff date usage in Python

Written by Arthur Camberlein | Published on & updated on
import difflib
import pandas as pd
from datetime import date

date = date.today()
today = date.strftime("%Y-%m-%d")
document = today + "-diff"
document_txt = "data/" + document + ".txt"
document_csv = "data/" + document + ".csv"

with open('robots-live.txt') as robots_live, open('robots-staging2.txt') as robots_staging:
    diff = difflib.unified_diff(
        robots_live.readlines(),
        robots_staging.readlines(),
        fromfile='robots-live.txt',
        tofile='robots-staging.txt',
    )

# for line in diff:
#     print(line)

with open(document_txt, 'w') as outfile:
    for line in diff:
        outfile.write(line)

df = pd.DataFrame(diff, columns=['diff'])
df.to_csv(document_csv, index=False)
Retour au blog

En savoir plus avec l'article FAQ

Diff date usage in Python - FAQ

Blog post taggued in: Data, Python

Written by