У меня есть 3 списка
user_list = ['Administrator', 'Deepak', 'Bhamar','Akash', 'Harshit']
group_members = [['Harshit', 'randam value', 40], ['Harshit', 'randam value', 40], ['Rohit', 'randam value', 40], ['Bhamar', 'randam value', 40], ['Akash', 'randam value', 40], ['Bhamar', 'randam value', 40], ['Bhamar', 'randam value', 40], ['Akash', 'randam value', 40], ['Harshit', 'randam value', 40]]
project_members = [['Administrator', 'random value', 50], ['Administrator', 'random value', 50], ['Administrator', 'random value', 50], ['Administrator', 'random value', 50], ['Administrator', 'random value', 50], ['Rakesh', 'random value', 30], ['Priyanka', 'random value', 30], ['Sapna', 'random value', 40], ['Amit', 'random value', 40]]
Теперь я хочу найти имена в списке "user_list" в "project_members" & "group_members" и вернуть соответствующие значения. Эти списки взяты из gitlab через apis, и я пытаюсь получить информацию о проектах и группах пользователей, и я совершенно новичок в python.
Я не могу получить логи c для достижения этой цели. .
ожидаемый результат в json:
Administrator:{
project:
[]
groups:{
[['Administrator', 'random value', 50], ['Administrator', 'random value', 50], ['Administrator', 'random value', 50], ['Administrator', 'random value', 50], ['Administrator', 'random value', 50], ['Rakesh', 'random value', 30]
Bhamar:{
projects:
[['Bhamar', 'randam value', 40],['Bhamar', 'randam value', 40],['Bhamar', 'randam value', 40]]
groups:
[]
код:
import gitlab
import csv
import os
gl = gitlab.Gitlab('git.gltlab.com', private_token='private_token')
with open("group.csv",'w+') as f:
pass
with open("project.csv",'w+') as f:
pass
group_list = []
project_list = []
group_members = []
project_members = []
user_list = []
def logging(file,data):
with open(os.path.join(file+".csv"),'a') as f:
wr = csv.writer(f, quoting=csv.QUOTE_ALL)
wr.writerow(data)
def main():
for page_no in range(1,4):
groups = gl.groups.list(per_page=5,page=page_no)
for id in groups:
group_list.append(id.name)
projects = gl.projects.list(per_page=9,page=page_no)
for project in projects:
project_list.append(project.id)
users = gl.users.list(per_page=1,page=page_no)
for user in users:
user_list.append(user)
get_group_members()
get_project_members()
def get_group_members():
for group in group_list:
group_1 = gl.groups.get(group)
grp_members = group_1.members.list()
for name in grp_members:
data = [str(name.name),str(group),name.access_level]
logging(file="group",data=data)
group_members.append(data)
def get_project_members():
for project in project_list:
project_1 = gl.projects.get(project)
prjt_memebrs = project_1.members.list()
for name in prjt_memebrs:
test = [str(name.name),str(project_1.name_with_namespace),name.access_level]
logging(file="project",data=test)
project_members.append(test)
if __name__ == "__main__":
main()