runnylib 0.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
runnylib-0.0.2/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2018 The Python Packaging Authority
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all
11
+ copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
+ SOFTWARE.
@@ -0,0 +1,16 @@
1
+ Metadata-Version: 2.4
2
+ Name: runnylib
3
+ Version: 0.0.2
4
+ Summary: just create file
5
+ Project-URL: Homepage, https://github.com/Runny1005/createfile
6
+ Project-URL: Issues, https://github.com/Runny1005/createfile/issues
7
+ Author-email: Runny1005 <passakorn.kus@gmail.com>
8
+ License-Expression: MIT
9
+ License-File: LICENSE
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.9
13
+ Description-Content-Type: text/markdown
14
+
15
+ # This is just a project that i made so i can use csv and json with auto file creation
16
+ yeah that's it
@@ -0,0 +1,2 @@
1
+ # This is just a project that i made so i can use csv and json with auto file creation
2
+ yeah that's it
@@ -0,0 +1,22 @@
1
+ [build-system]
2
+ requires = ["hatchling >= 1.26"]
3
+ build-backend = "hatchling.build"
4
+ [project]
5
+ name = "runnylib"
6
+ version = "0.0.2"
7
+ authors = [
8
+ { name="Runny1005", email="passakorn.kus@gmail.com" },
9
+ ]
10
+ description = "just create file"
11
+ readme = "README.md"
12
+ requires-python = ">=3.9"
13
+ classifiers = [
14
+ "Programming Language :: Python :: 3",
15
+ "Operating System :: OS Independent",
16
+ ]
17
+ license = "MIT"
18
+ license-files = ["LICEN[CS]E*"]
19
+
20
+ [project.urls]
21
+ Homepage = "https://github.com/Runny1005/createfile"
22
+ Issues = "https://github.com/Runny1005/createfile/issues"
File without changes
@@ -0,0 +1,26 @@
1
+ import csv
2
+ from pathlib import Path
3
+ from datetime import datetime
4
+ import os
5
+ path=os.getcwd()
6
+
7
+ def create_file(topic,field,path):
8
+ for i in range(len(topic)):
9
+ file=topic[i]
10
+ file=path+file.replace('/','-')+'.csv'
11
+ print(file)
12
+ Path(file).parent.mkdir(exist_ok=True,parents=True)
13
+ with open(file,"w",newline='',encoding='utf-8') as f:
14
+ writer=csv.DictWriter(f,fieldnames=field)
15
+ writer.writeheader()
16
+ def write_to_file(msg,field,path):
17
+ file=msg.topic
18
+ file=path+file.replace('/','-')+".csv"
19
+ try:
20
+ value=msg.payload.decode()
21
+ timestamp=datetime.now().strftime("%Y/%m/%d %H:%M:%S")
22
+ with open(file,'a',newline='',encoding="utf-8") as f:
23
+ writer=csv.DictWriter(f,fieldnames=field)
24
+ writer.writerow({"Data":timestamp,"Timestamp":value})
25
+ except Exception as e:
26
+ print("Error With error code :",e)
@@ -0,0 +1,25 @@
1
+ import json
2
+ from pathlib import Path
3
+ from datetime import datetime
4
+ import os
5
+ path=os.getcwd()
6
+ def create_file(topic,path):
7
+ for i in range(len(topic)):
8
+ file=topic[i]
9
+ file=path+file.replace('/','-')+".json"
10
+ print(file)
11
+ Path(file).parent.mkdir(exist_ok=True,parents=True)
12
+ with open(file,"w",newline='',encoding='utf-8') as f:
13
+ f.write([])
14
+
15
+
16
+ def write_to_file(msg,path):
17
+ file=msg.topic
18
+ file=path+file.replace('/','-')+".csv"
19
+ try:
20
+ val=msg.payload.decode()
21
+ timestamp=datetime.now().strftime("%Y/%m/%d %H:%M:%S")
22
+ with open(file,'a',newline='',encoding="utf-8") as f:
23
+ json.dump({'Time':timestamp,'Data':val})
24
+ except Exception as e:
25
+ print("Error With error code :",e)