forked from ritwik12/Virtual-Assistant
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathresponse.c
More file actions
149 lines (125 loc) · 4.63 KB
/
Copy pathresponse.c
File metadata and controls
149 lines (125 loc) · 4.63 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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
/*
* File: response.c
*
* Created on April 10, 2018, 8:51 AM
*/
if ((strcmp(result, "greeting") == 0)) {
system("say I am good");
printf("I am good \n");
} else if (strcmp(str, "firefox") == 0 || strcmp(str, "open firefox") == 0 || strcmp(str, "run firefox") == 0 || strcmp(str, "start firefox") == 0) {
system("say opening firefox");
system("firefox");
} else if ((strcmp(str, "vlc") == 0) || (strcmp(str, "open vlc") == 0) || (strcmp(str, "run vlc") == 0) || (strcmp(str, "start vlc") == 0)) {
system("say opening vlc");
system("vlc");
}// Weather
else if ((strcmp(result, "weather") == 0)) {
printf("Please enter location to get weather forecast \n");
fgets(location, 1000, stdin);
system("say showing weather");
sprintf(weather, "http://wttr.in/\%s", location);
int counter_weather = 0;
while (weather[counter_weather] != '\n') {
counter_weather++;
}
weather[counter_weather] = '\0';
show_weather(weather);
//system(weather);
} else if (strstr(str, "search youtube") != NULL) {
//Extract substring after "FOR"
len = strlen(str);
strncpy(youtube, str + 19, len);
//Youtube search
//-------------------------------------------------
start = malloc(strlen(youtube) + 1);
pv = 0; //previous character
for (d = c = 0; youtube[c]; ++c) {
if (youtube[c] == SPACE) {
if (pv != SPACE)
start[d++] = '+';
pv = SPACE;
} else {
pv = start[d++] = youtube[c];
}
}
start[d] = '\0';
//--------------------------------
sprintf(buff, "say searching youtube for \%s", youtube);
system(buff);
sprintf(buf, "%s https://www.youtube.com/results?search_query=\%s", WebBrowser, start);
system(buf);
} else if ((strcmp(result, "media") == 0)) {
system("say here are the list of available media");
printf("Here are the list of available media\n");
char * sys_cmd1;
char sys_cmd[1000];
sys_cmd1 = "ls ";
sprintf(sys_cmd, "%s%s%s", sys_cmd1, HOME_DIR, "media/");
system(sys_cmd);
system("say which media do you want me to play");
printf("Which media do you want me to play? \n");
fgets(songs, 1000, stdin);
sprintf(song, "%s %smedia/\%s", M_P, HOME_DIR, songs);
system(song);
} else if ((strcmp(str, "calendar") == 0) || (strcmp(str, "open calendar") == 0)) {
system("say which year calendar you want to see");
printf("Which year calendar you want to see? \n");
fgets(cal, 1000, stdin);
sprintf(calendar, "cal \%s", cal);
system(calendar);
}//Restaurant
else if ((strcmp(result, "restaurant")) == 0) {
find_restaurants();
}else if((strcmp(result, "email") == 0)){
email();
} //Help
else if ((strcmp(str, "help") == 0)) {
char * help1 = "less ";
char help[1000];
sprintf(help, "%s%s%s", help1, HOME_DIR, "help.txt");
system(help);
} else if ((strcmp(result, "google") == 0)) {
printf("google command\n");
if ((google_score == 0) && (greeting_score == 0) && (email_score == 0) && (weather_score == 0) && (media_score == 0)) {
// fgets (search, 1000, stdin);
//-------------------------------------------------
start = malloc(strlen(str) + 1);
pv = 0; //previous character
for (d = c = 0; str[c]; ++c) {
if (str[c] == SPACE) {
if (pv != SPACE)
start[d++] = '+';
pv = SPACE;
} else {
pv = start[d++] = str[c];
}
}
start[d] = '\0';
if (strcmp(str, "stop") != 0) {
//--------------------------------
sprintf(buff, "say Do you mean \%s", str);
system(buff);
sprintf(buf, "%s https://www.google.co.in/search?q=%s&ie=utf-8&oe=utf-8&client=firefox-b-ab&gfe_rd=cr&ei=zkWgWc3fNeXI8AeCr5LYBw ", WebBrowser, start);
system(buf);
}
} else {
printf("What can I search for you on Google?\n");
fgets(search, 1000, stdin);
//-------------------------------------------------
start = malloc(strlen(str) + 1);
pv = 0; //previous character
for (d = c = 0; search[c]; ++c) {
if (search[c] == SPACE) {
if (pv != SPACE)
start[d++] = '+';
pv = SPACE;
} else {
pv = start[d++] = search[c];
}
}
start[d] = '\0';
//--------------------------------
sprintf(buf, "%s https://www.google.co.in/search?q=%s&ie=utf-8&oe=utf-8&client=firefox-b-ab&gfe_rd=cr&ei=zkWgWc3fNeXI8AeCr5LYBw ", WebBrowser, start);
system(buf);
}
}