-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddAuthorInfo.cpp
More file actions
99 lines (80 loc) · 2.64 KB
/
addAuthorInfo.cpp
File metadata and controls
99 lines (80 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*
Author: Dabananda Mitra
Email: dabananda.dev@gmail.com
GitHub: https://github.com/dabananda
LinkedIn: https://www.linkedin.com/in/dabanandamitra/
Portfolio: https://dmitra.netlify.app/
Department of Computer Science and Engineering (CSE), Session: 2019-2020, Institute of Science Trade & Technology (ISTT)
Time & Date: 2026-02-07 09:34:36 AM (Dhaka, Bangladesh)
*/
/*
Author: Dabananda Mitra
Email: imdmitra@gmail.com
GitHub: https://github.com/dabananda
LinkedIn: https://www.linkedin.com/in/dabanandamitra/
Department of Computer Science and Engineering (CSE), Session: 2019-2020, Institute of Science Trade & Technology (ISTT)
Time & Date: 2024-03-04 03:23:31 PM (Dhaka, Bangladesh)
*/
#include <ctime>
#include <fstream>
#include <iostream>
#include <sstream>
#include <string>
using namespace std;
string getCurrentDateTime() {
time_t now = time(0);
struct tm* localTime = localtime(&now);
char buffer[80];
strftime(buffer, sizeof(buffer), "%Y-%m-%d %I:%M:%S %p", localTime);
return buffer;
}
int main() {
string filePath;
string authorInfo =
"/*\n"
"Author: Dabananda Mitra\n"
"Email: dabananda.dev@gmail.com\n"
"GitHub: https://github.com/dabananda\n"
"LinkedIn: https://www.linkedin.com/in/dabanandamitra/\n"
"Portfolio: https://dmitra.netlify.app/\n"
"Department of Computer Science and Engineering (CSE), Session: 2019-2020, Institute of Science Trade & Technology (ISTT)\n"
"Time & Date: " +
getCurrentDateTime() +
" (Dhaka, Bangladesh)\n"
"*/\n\n";
// Input file path
cout << "Enter the file path: ";
getline(cin, filePath);
// Open the file
ifstream inputFile(filePath);
if (!inputFile.is_open()) {
cerr << "Error opening file: " << filePath << endl;
return 1;
}
// Read the content of the file
stringstream buffer;
buffer << inputFile.rdbuf();
string fileContent = buffer.str();
// Add author information at the beginning
fileContent = authorInfo + fileContent;
// Close the input file
inputFile.close();
// Open the file for writing
ofstream outputFile(filePath);
if (!outputFile.is_open()) {
cerr << "Error opening file for writing: " << filePath << endl;
return 1;
}
// Write the modified content to the file
outputFile << fileContent;
// Close the output file
outputFile.close();
// Commit and push to GitHub
string commitMessage;
cout << "Enter the commit message: ";
getline(cin, commitMessage);
string command = "git add " + filePath + " && git commit -m \"" + commitMessage + "\" && git push";
system(command.c_str());
cout << "Changes committed and pushed to GitHub successfully." << endl;
return 0;
}