simonduerr commited on
Commit
b3b13a6
·
1 Parent(s): a6bff4f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -6
app.py CHANGED
@@ -97,17 +97,33 @@ def process_and_create_pull(icon_files,category, new_cateogry_check, new_categor
97
  sha=index_file.sha,
98
  branch=branch_name
99
  )
 
 
 
 
 
 
 
 
 
 
100
  for file in icon_files:
101
  #get file content from filesystem
102
  with open(file.name, 'r') as fp:
103
  file_content = fp.read()
104
  filename = os.path.basename(file.name).replace(" ", "_")
105
- site.create_file(
106
- path=f'static/icons/{license}/{category}/{author}/{filename}',
107
- message=f'create {filename}',
108
- content=file_content,
109
- branch=branch_name
110
- )
 
 
 
 
 
 
111
  pull = create_pull_request(site,branch_name, github_user)
112
  return f"""<link href="https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.6.4/flowbite.min.css" rel="stylesheet" />
113
  <div class="flex p-4 mb-4 text-sm text-green-800 rounded-lg bg-green-200 " role="alert">
 
97
  sha=index_file.sha,
98
  branch=branch_name
99
  )
100
+ all_files = []
101
+ contents = repo.get_contents("static/icons/{license}/{category}/{author}/")
102
+ while contents:
103
+ file_content = contents.pop(0)
104
+ if file_content.type == "dir":
105
+ contents.extend(repo.get_contents(file_content.path))
106
+ else:
107
+ file = file_content
108
+ all_files.append(str(file).replace('ContentFile(path="','').replace('")',''))
109
+ print("files in directory": all_files)
110
  for file in icon_files:
111
  #get file content from filesystem
112
  with open(file.name, 'r') as fp:
113
  file_content = fp.read()
114
  filename = os.path.basename(file.name).replace(" ", "_")
115
+ git_file = f'static/icons/{license}/{category}/{author}/{filename}'
116
+ if git_file in all_files:
117
+ contents = site.get_contents(git_file)
118
+ site.update_file(contents.path, f'update {filename}', file_content, contents.sha, branch=branch_name)
119
+ print(git_file + ' UPDATED')
120
+ else:
121
+ site.create_file(
122
+ path=git_file,
123
+ message=f'create {filename}',
124
+ content=file_content,
125
+ branch=branch_name
126
+ )
127
  pull = create_pull_request(site,branch_name, github_user)
128
  return f"""<link href="https://cdnjs.cloudflare.com/ajax/libs/flowbite/1.6.4/flowbite.min.css" rel="stylesheet" />
129
  <div class="flex p-4 mb-4 text-sm text-green-800 rounded-lg bg-green-200 " role="alert">