
import subprocess
from datetime import datetime

changes_by_date = {}
git_log = subprocess.Popen(
    'git log --numstat --pretty="%at"',
    stdout=subprocess.PIPE,
    shell=True)

date = None
day_changes = [0, 0]
for line in git_log.stdout:
    args = line.rstrip().split()
    if len(args) == 1:
        old_date = date
        date = datetime.fromtimestamp(int(args[0]))
        if day_changes != [0, 0] and date.date() != old_date.date():
            changes_by_date[str(date.date())] = day_changes
            day_changes = [0, 0]
    elif len(args) >= 3:
        day_changes = [sum(x) for x in zip(day_changes, map(int, args[0:2]))]

print('date,ins,del')
for key,vals in changes_by_date.items():
    print(','.join(map(str, [key, vals[0], vals[1]])))


import subprocess
from datetime import datetime

def chomp_int(val):
    try:
        return int(val)
    except ValueError:
        return 0

changes_by_date = {}
git_log = subprocess.Popen(
    'git log --numstat --pretty="%at"',
    stdout=subprocess.PIPE,
    shell=True)

date = None
day_changes = [0, 0]
for line in git_log.stdout:
    args = line.rstrip().split()
    if len(args) == 1:
        old_date = date
        date = datetime.fromtimestamp(int(args[0]))
        if day_changes != [0, 0] and date.date() != old_date.date():
            changes_by_date[str(date.date())] = day_changes
            day_changes = [0, 0]
    elif len(args) >= 3:
        day_changes = [sum(x) for x in zip(day_changes, map(chomp_int, args[0:2]))]

print('date,ins,del')
for key,vals in changes_by_date.items():
    print(','.join(map(str, [key, vals[0], vals[1]])))

Fix script for repos with binaries
Fix script for repos with binaries

  
  import subprocess
  from datetime import datetime
+ 
+ def chomp_int(val):
+     try:
+         return int(val)
+     except ValueError:
+         return 0
  
  changes_by_date = {}
  git_log = subprocess.Popen(
      'git log --numstat --pretty="%at"',
      stdout=subprocess.PIPE,
      shell=True)
  
  date = None
  day_changes = [0, 0]
  for line in git_log.stdout:
      args = line.rstrip().split()
      if len(args) == 1:
          old_date = date
          date = datetime.fromtimestamp(int(args[0]))
          if day_changes != [0, 0] and date.date() != old_date.date():
              changes_by_date[str(date.date())] = day_changes
              day_changes = [0, 0]
      elif len(args) >= 3:
-         day_changes = [sum(x) for x in zip(day_changes, map(int, args[0:2]))]
+         day_changes = [sum(x) for x in zip(day_changes, map(chomp_int, args[0:2]))]
  
  print('date,ins,del')
  for key,vals in changes_by_date.items():
      print(','.join(map(str, [key, vals[0], vals[1]])))
  
Fix script for repos with binaries
## Code Before:

import subprocess
from datetime import datetime

changes_by_date = {}
git_log = subprocess.Popen(
    'git log --numstat --pretty="%at"',
    stdout=subprocess.PIPE,
    shell=True)

date = None
day_changes = [0, 0]
for line in git_log.stdout:
    args = line.rstrip().split()
    if len(args) == 1:
        old_date = date
        date = datetime.fromtimestamp(int(args[0]))
        if day_changes != [0, 0] and date.date() != old_date.date():
            changes_by_date[str(date.date())] = day_changes
            day_changes = [0, 0]
    elif len(args) >= 3:
        day_changes = [sum(x) for x in zip(day_changes, map(int, args[0:2]))]

print('date,ins,del')
for key,vals in changes_by_date.items():
    print(','.join(map(str, [key, vals[0], vals[1]])))

## Instruction:
Fix script for repos with binaries
## Code After:

import subprocess
from datetime import datetime

def chomp_int(val):
    try:
        return int(val)
    except ValueError:
        return 0

changes_by_date = {}
git_log = subprocess.Popen(
    'git log --numstat --pretty="%at"',
    stdout=subprocess.PIPE,
    shell=True)

date = None
day_changes = [0, 0]
for line in git_log.stdout:
    args = line.rstrip().split()
    if len(args) == 1:
        old_date = date
        date = datetime.fromtimestamp(int(args[0]))
        if day_changes != [0, 0] and date.date() != old_date.date():
            changes_by_date[str(date.date())] = day_changes
            day_changes = [0, 0]
    elif len(args) >= 3:
        day_changes = [sum(x) for x in zip(day_changes, map(chomp_int, args[0:2]))]

print('date,ins,del')
for key,vals in changes_by_date.items():
    print(','.join(map(str, [key, vals[0], vals[1]])))
