FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
event-registry-python/eventregistry/QueryArticle.py at master · EventRegistry/event-registry-python · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
EventRegistry
/
event-registry-python
Public
Notifications
You must be signed in to change notification settings
Fork
57
Star
259
Code
Issues
3
Pull requests
0
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
event-registry-python
/
eventregistry
/
QueryArticle.py
Copy path
More file actions
More file actions
Latest commit
History
History
History
129 lines (105 loc) · 5.43 KB
Breadcrumbs
event-registry-python
/
eventregistry
/
QueryArticle.py
Copy path
File metadata and controls
129 lines (105 loc) · 5.43 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
from
eventregistry
.
Base
import
*
from
eventregistry
.
ReturnInfo
import
*
from
typing
import
List
,
Union
class
QueryArticle
(
Query
):
def
__init__
(
self
,
articleUriOrUriList
:
Union
[
str
,
List
[
str
]],
requestedResult
:
Union
[
"RequestArticle"
,
None
]
=
None
):
"""
Class for obtaining available info for one or more articles in the Event Registry
@param articleUriOrUriList: a single article uri or a list of article uris
@param requestedResult: the information to return as the result of the query. By default return the information about the article
"""
super
(
QueryArticle
,
self
).
__init__
()
self
.
_setVal
(
"articleUri"
,
articleUriOrUriList
)
self
.
_setVal
(
"action"
,
"getArticle"
)
self
.
setRequestedResult
(
requestedResult
or
RequestArticleInfo
())
def
_getPath
(
self
):
return
"/api/v1/article"
@
staticmethod
def
queryByUri
(
articleUriOrUriList
:
Union
[
str
,
List
[
str
]]):
"""
obtain information about one or more articles by providing their article uris (newsfeed ids, such as "284017606")
@param articleUriOrUriList: single article uri or a list of article uris to query
"""
q
=
QueryArticle
([])
q
.
queryParams
[
"articleUri"
]
=
articleUriOrUriList
return
q
def
setRequestedResult
(
self
,
requestArticle
:
"RequestArticle"
):
"""
Set the single result type that you would like to be returned. If some other request type was previously set, it will be overwritten.
Result types can be the classes that extend RequestArticle base class (see classes below).
"""
assert
isinstance
(
requestArticle
,
RequestArticle
),
"QueryArticle class can only accept result requests that are of type RequestArticle"
self
.
resultTypeList
=
[
requestArticle
]
class
RequestArticle
:
def
__init__
(
self
):
self
.
resultType
=
None
def
getResultType
(
self
):
return
self
.
resultType
class
RequestArticleInfo
(
RequestArticle
):
def
__init__
(
self
,
returnInfo
:
ReturnInfo
=
ReturnInfo
(
articleInfo
=
ArticleInfoFlags
(
bodyLen
=
-
1
))):
"""
return details about the article
@param returnInfo: what details should be included in the returned information
"""
super
(
RequestArticle
,
self
).
__init__
()
self
.
resultType
=
"info"
self
.
__dict__
.
update
(
returnInfo
.
getParams
(
"info"
))
class
RequestArticleSimilarArticles
(
RequestArticle
):
def
__init__
(
self
,
page
:
int
=
1
,
count
:
int
=
20
,
lang
:
Union
[
str
,
List
[
str
]]
=
[
"eng"
],
limitPerLang
:
int
=
-
1
,
returnInfo
:
ReturnInfo
=
ReturnInfo
(
articleInfo
=
ArticleInfoFlags
(
bodyLen
=
-
1
))):
"""
return a list of similar articles based on the CCA
@param page: page of the articles
@param count: number of articles to return (at most 200)
@param lang: in which language(s) should be the similar articles
@param limitPerLang: max number of articles per language to return (-1 for no limit)
@param returnInfo: what details should be included in the returned information
"""
super
(
RequestArticle
,
self
).
__init__
()
assert
page
>=
1
,
"page has to be >= 1"
assert
count
<=
200
,
"at most 200 articles can be returned per call"
self
.
resultType
=
"similarArticles"
self
.
similarArticlesPage
=
page
self
.
similarArticlesCount
=
count
self
.
similarArticlesLang
=
lang
self
.
similarArticlesLimitPerLang
=
limitPerLang
self
.
__dict__
.
update
(
returnInfo
.
getParams
(
"similarArticles"
))
class
RequestArticleDuplicatedArticles
(
RequestArticle
):
def
__init__
(
self
,
page
:
int
=
1
,
count
:
int
=
20
,
sortBy
:
str
=
"cosSim"
,
sortByAsc
:
bool
=
False
,
returnInfo
:
ReturnInfo
=
ReturnInfo
(
articleInfo
=
ArticleInfoFlags
(
bodyLen
=
-
1
))):
"""
return a list of duplicated articles of the current article
@param page: page of the articles
@param count: number of articles to return (at most 200)
@param sortBy: how are the articles sorted. Options: id, date, cosSim, fq, socialScore, facebookShares, twitterShares
@param sortByAsc: should the results be sorted in ascending order (True) or descending (False)
@param returnInfo: what details should be included in the returned information
"""
super
(
RequestArticle
,
self
).
__init__
()
assert
page
>=
1
,
"page has to be >= 1"
assert
count
<=
200
,
"at most 200 articles can be returned per call"
self
.
resultType
=
"duplicatedArticles"
self
.
duplicatedArticlesPage
=
page
self
.
duplicatedArticlesCount
=
count
self
.
duplicatedArticlesSortBy
=
sortBy
self
.
duplicatedArticlesSortByAsc
=
sortByAsc
self
.
__dict__
.
update
(
returnInfo
.
getParams
(
"duplicatedArticles"
))
class
RequestArticleOriginalArticle
(
RequestArticle
):
def
__init__
(
self
,
returnInfo
:
ReturnInfo
=
ReturnInfo
(
articleInfo
=
ArticleInfoFlags
(
bodyLen
=
-
1
))):
"""
return the article that is the original of the given article (the current article is a duplicate)
@param returnInfo: what details should be included in the returned information
"""
super
(
RequestArticle
,
self
).
__init__
()
self
.
resultType
=
"originalArticle"
self
.
__dict__
.
update
(
returnInfo
.
getParams
(
"originalArticle"
))
Back
|
FazBrowse Home
|
New Git URL