Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit e3f7414

Browse files
Added new script
1 parent 8d76479 commit e3f7414

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

‎README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,8 @@ Pune, Maharashtra, India.<br />
9090
9. [Birthday Reminder](https://github.com/OmkarPathak/Python-Programs/blob/master/Scripts/P09_ReminderApplication.py)
9191
10. [Script to download tutorial from tutorials point](https://github.com/OmkarPathak/Python-Programs/blob/master/Scripts/P10_SciptToDownloadPDF.py)
9292
11. [Script to check email in your terminal](https://github.com/OmkarPathak/Python-Programs/blob/master/Scripts/P11_CheckEmail.py)
93+
12. [Script to find devices connected to Network](https://github.com/OmkarPathak/Python-Programs/blob/master/Scripts/P12_ScriptToFindDevicesConnectedInNetwork.py)
94+
13. [Script to create metadata for a file](https://github.com/OmkarPathak/Python-Programs/blob/master/Scripts/P13_Python_Create_File_With_Metadata.py)
9395

9496
## Python Concepts
9597

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#!/usr/bin/python3.6
2+
import sys, os, datetime
3+
4+
def create_file(file_name):
5+
'''
6+
Create a flat file based on underlying Operating System
7+
'''
8+
if sys.platform == 'linux' or sys.platform == 'darwin':
9+
os.system('touch ' + file_name)
10+
elif sys.platform == 'win32':
11+
os.system('echo . > ' + file_name)
12+
13+
def write_data_in_file(file_name):
14+
'''
15+
Write the metadata into the file
16+
'''
17+
if sys.argv[3]:
18+
if len(sys.argv[3]) <= 15:
19+
length = 15
20+
else:
21+
length = len(sys.argv[3])
22+
else:
23+
length = 15
24+
with open(file_name, 'w') as fd:
25+
fd.write('#' * (length + 16))
26+
fd.write('\n# Author: ' + sys.argv[2])
27+
fd.write('\n# Description: ' + sys.argv[3])
28+
fd.write('\n# Created at: ' + datetime.datetime.today().strftime('%d %b %Y') + '\n')
29+
fd.write('#' * (length + 16))
30+
31+
if __name__ == '__main__':
32+
if len(sys.argv) <= 3:
33+
print('You need to provide three arguments [File Name] [Author Name] [Description]')
34+
exit()
35+
create_file(sys.argv[1])
36+
write_data_in_file(sys.argv[1])

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /