Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please convert this python2 code to python3 from datetime import datetime, timed

ID: 3722310 • Letter: P

Question

Please convert this python2 code to python3

from datetime import datetime, timedelta
import json

from p1 import find_highest

# Below three are for the graphs (remove it if you dont want this)
import matplotlib
import matplotlib.pyplot as plt
import numpy as np

def get_highest_week_data(filename):
week_data = find_highest(filename)
date = datetime.fromtimestamp(int(week_data['week'])).strftime('%Y-%m-%d')
all_days = {}
for curr_day, count in enumerate(week_data['days']):
  curr_date = (datetime.strptime(date, '%Y-%m-%d') + timedelta(days=curr_day)).strftime('%Y-%m-%d')
  all_days[curr_date] = count

return all_days

if __name__ == "__main__":
data = get_highest_week_data('commit_activity.json')
print data

# Code for plotting graph (Remove it, if don't want the graph)
x = []
y = []
for date, count in enumerate(data):
  x.append(date)
  y.append(count)

plt.plot(y, x)
plt.gcf().autofmt_xdate()
plt.show()

Explanation / Answer

from datetime import datetime, timedelta import matplotlib.pyplot as plt from p1 import find_highest def get_highest_week_data(filename): week_data = find_highest(filename) date = datetime.fromtimestamp(int(week_data['week'])).strftime('%Y-%m-%d') all_days = {} for curr_day, count in enumerate(week_data['days']): curr_date = (datetime.strptime(date, '%Y-%m-%d') + timedelta(days=curr_day)).strftime('%Y-%m-%d') all_days[curr_date] = count return all_days if __name__ == "__main__": data = get_highest_week_data('commit_activity.json') print(data) # Code for plotting graph (Remove it, if don't want the graph) x = [] y = [] for date, count in enumerate(data): x.append(date) y.append(count) plt.plot(y, x) plt.gcf().autofmt_xdate() plt.show()

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote