Created
January 4, 2022 02:00
-
-
Save Kimjunkuk/2186c3a05d4d541a57b13759df7ae8ec to your computer and use it in GitHub Desktop.
Uploading the descriptions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import os, requests, json | |
| def catalog_data(url, description_dir): | |
| fruit={} | |
| for item in os.listdir(description_dir): # 문제 | |
| fruit.clear() | |
| filename=os.path.join(description_dir,item) | |
| with open(filename) as f: | |
| line=f.readlines() | |
| description="" | |
| for i in range(2,len(line)): | |
| description=description+line[i].strip('\n').replace(u'\xa0',u'') | |
| fruit["description"]=description | |
| fruit["weight"]=int(line[1].strip('\n').strip('lbs')) | |
| fruit["name"]=line[0].strip('\n') | |
| fruit["image_name"]=(item.strip('.txt'))+'.jpeg' | |
| print(fruit) | |
| if url!="": | |
| response=requests.post(url, json=fruit) | |
| print(response.request.url) | |
| print(response.status_code) | |
| return 0 | |
| if __name__=='__main__': | |
| url='http://localhost/fruits/' | |
| user = os.getenv('USER') | |
| description_directory = '/home/{}/supplier-data/descriptions/'.format(user) | |
| catalog_data(url, description_directory) #문제 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment