Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Pédagogies Multimodales
wikicolor
Commits
8fff8fe3
Commit
8fff8fe3
authored
Aug 07, 2022
by
Sylvain Coulange
🌼
Browse files
ajout appstat agent country
parent
12faee28
Changes
2
Hide whitespace changes
Inline
Side-by-side
colorapp/textPhonographer.py
View file @
8fff8fe3
...
...
@@ -602,12 +602,14 @@ def writeLog(Type,user,mot,oldMot,newMot,lang):
print
(
"New log: lang={} ; user={} ; word={} ; type={}"
.
format
(
lang
,
user
,
mot
,
Type
))
return
noIdDict
(
newlog
)
def
addStat
(
app
,
module
,
ip
,
lang
):
def
addStat
(
app
,
module
,
ip
,
agent
,
country
,
lang
):
newStat
=
{
'date'
:
datetime
.
datetime
.
now
(),
'app'
:
app
,
'module'
:
module
,
'ip'
:
ip
,
'agent'
:
agent
,
'country'
:
country
,
'lang'
:
lang
}
if
ip
!=
"127.0.0.1"
:
users_appstats
.
insert_one
(
newStat
)
\ No newline at end of file
users_appstats
.
insert_one
(
newStat
)
\ No newline at end of file
colorapp/views.py
View file @
8fff8fe3
...
...
@@ -4,7 +4,8 @@ from .models import Phonograph, Data, Entree, commitData
from
django.http
import
JsonResponse
from
.liaisons
import
*
from
.english_spacyExceptions
import
getOneWordList
import
json
,
spacy
,
subprocess
,
re
import
json
,
spacy
,
subprocess
,
re
,
requests
from
user_agents
import
parse
print
(
'Chargement des modèles de langue...'
)
print
(
'fr_core_news_md...'
)
...
...
@@ -348,12 +349,28 @@ def getLog(request):
return
JsonResponse
({
"logs"
:
rep
})
def
addStat
(
request
):
colis
=
json
.
loads
(
request
.
body
)
app
=
colis
[
"app"
]
module
=
colis
[
"module"
]
ip
=
get_client_ip
(
request
)
lang
=
colis
[
"lang"
]
txtphono
.
addStat
(
app
,
module
,
ip
,
lang
)
if
get_client_ip
(
request
)
!=
"127.0.0.1"
:
colis
=
json
.
loads
(
request
.
body
)
app
=
colis
[
"app"
]
module
=
colis
[
"module"
]
ip
=
get_client_ip
(
request
)
agent
=
parse
(
request
.
META
[
'HTTP_USER_AGENT'
])
country
=
getCountry
(
get_client_ip
(
request
))
lang
=
colis
[
"lang"
]
txtphono
.
addStat
(
app
,
module
,
ip
,
agent
,
country
,
lang
)
return
JsonResponse
({})
def
getCountry
(
ip
):
endpoint
=
f
'https://ipinfo.io/
{
ip
}
/json'
response
=
requests
.
get
(
endpoint
,
verify
=
True
)
if
response
.
status_code
!=
200
:
return
'Status:'
,
response
.
status_code
,
'Problem with the request. Exiting.'
exit
()
return
JsonResponse
({})
\ No newline at end of file
data
=
response
.
json
()
print
(
data
)
return
data
[
'country'
]
\ No newline at end of file
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment