|
@@ -105,11 +105,15 @@ class efactTest(unittest.TestCase):
|
|
def test_renamer(self, dir_path, kind: Union[str, 'seller', 'buyer']): # @UndefinedVariable
|
|
def test_renamer(self, dir_path, kind: Union[str, 'seller', 'buyer']): # @UndefinedVariable
|
|
if kind == 'seller':
|
|
if kind == 'seller':
|
|
account = 'AccountingCustomerParty'
|
|
account = 'AccountingCustomerParty'
|
|
|
|
+ # print(os.path.basename(dir_path))
|
|
|
|
+ dir_path = os.path.join(dir_path, os.path.basename(dir_path))
|
|
else:
|
|
else:
|
|
account = 'AccountingSupplierParty'
|
|
account = 'AccountingSupplierParty'
|
|
|
|
+ # next_subfolder = next(os.walk(dir_path))[1][0]
|
|
for root_f, _dirs, files in os.walk(dir_path):
|
|
for root_f, _dirs, files in os.walk(dir_path):
|
|
for file in files:
|
|
for file in files:
|
|
- if file.endswith('.xml') and '_' not in file:
|
|
|
|
|
|
+ # print(root_f)
|
|
|
|
+ if file.endswith('.xml') and file.count('_') < 2:
|
|
# print(os.path.join(root, file))
|
|
# print(os.path.join(root, file))
|
|
tree = etree.parse(os.path.join(root_f, file))
|
|
tree = etree.parse(os.path.join(root_f, file))
|
|
root = tree.getroot()
|
|
root = tree.getroot()
|
|
@@ -133,14 +137,23 @@ class efactTest(unittest.TestCase):
|
|
file_id = partie_id.text
|
|
file_id = partie_id.text
|
|
new_name = '{}_{}_{}_{}.xml'.format(file.replace('.xml', ''), file_id, file_partie, is_date)
|
|
new_name = '{}_{}_{}_{}.xml'.format(file.replace('.xml', ''), file_id, file_partie, is_date)
|
|
current_path = os.path.join(root_f, file)
|
|
current_path = os.path.join(root_f, file)
|
|
- print(new_name)
|
|
|
|
new_path = os.path.join(root_f, new_name)
|
|
new_path = os.path.join(root_f, new_name)
|
|
- os.rename(current_path, new_path)
|
|
|
|
|
|
+ if kind == 'buyer':
|
|
|
|
+ path_parts = root_f.split('/')
|
|
|
|
+ seventh_part = path_parts[7] if len(path_parts) > 6 else None
|
|
|
|
+ # print(seventh_part)
|
|
|
|
+ if seventh_part != os.path.basename(dir_path):
|
|
|
|
+ # os.rename(current_path, new_path)
|
|
|
|
+ print(new_name)
|
|
|
|
+ else:
|
|
|
|
+ # os.rename(current_path, new_path)
|
|
|
|
+ print(new_name)
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
if __name__ == "__main__":
|
|
# unittest.main()
|
|
# unittest.main()
|
|
# efactTest().test_add_invoice()
|
|
# efactTest().test_add_invoice()
|
|
# efactTest().test_get_all_messages()
|
|
# efactTest().test_get_all_messages()
|
|
- efactTest().test_renamer('c:/Users/levi/git/anafapi/tests/17259191/', kind='seller')
|
|
|
|
|
|
+ # efactTest().test_renamer('c:/Users/levi/git/anafapi/tests/17259191/', kind='seller')
|
|
|
|
+ efactTest().test_renamer('/home/deeejas/git/anafapi/tests/17259191', kind='buyer')
|
|
# anoauth.get_token()
|
|
# anoauth.get_token()
|