-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
65 lines (52 loc) · 1.43 KB
/
main.c
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
#include <stdio.h>
#include <stdlib.h>
#include <Python.h>
void nl_processor(FILE file); // ideally, put this in 'main.h' file
int main(int argc, char *argv[])
{
wchar_t *program = Py_DecodeLocale(argv[0], NULL);
if (program == NULL) {
fprintf(stderr, "Fatal error: cannot decode argv[0]\n");
exit(1);
}
Py_SetProgramName(program); // optional
Py_Initialize();
wchar_t *args[argc];
for (int i = 0; i < argc; i++) {
args[i] = Py_DecodeLocale(argv[i], NULL);
}
PySys_SetArgv(argc, args);
FILE *py_file = NULL;
py_file = fopen("./main.py", "r");
if (py_file != NULL) {
PyImport_ImportModule("bs4");
PyImport_ImportModule("requests");
PyRun_SimpleFile(py_file, "main");
Py_Finalize();
PyMem_RawFree(program);
}
else {
printf("Fail to open Python file. Please, check if it exists...");
return 1;
}
FILE *source = NULL;
source = fopen("content.txt", "r");
if (source != NULL) {
nl_processor(*source);
}
else {
printf("Fail to open text file.");
return 1;
}
printf("\n*** Task completed! ***");
return 0;
}
void nl_processor(FILE source)
{
printf("-> Beginning NLP...\n");
// do some complicated NLP here...
// save results to a file
// or whatever... :)
sleep(2); // simulate 2 seconds of processing
printf("\n-> NLP completed.\n");
}