Skip to content

Commit 7804e2e

Browse files
committed
fixup index name
1 parent e88e82c commit 7804e2e

File tree

2 files changed

+54
-2
lines changed

2 files changed

+54
-2
lines changed

import_projects.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
import requests
2+
from django.contrib.auth.models import User
3+
from requests import ConnectionError
4+
5+
from readthedocs.core.utils import trigger_build
6+
from readthedocs.projects.models import Project
7+
8+
base_url = "http://readthedocs.org/api/v2/project/"
9+
COUNT = 0
10+
11+
12+
def create_project(repo, name, repo_type):
13+
user = User.objects.all().get(username="safwan")
14+
try:
15+
p = Project.objects.create(repo=repo, name=name, repo_type=repo_type)
16+
trigger_build(p, basic=True)
17+
p.users.add(user)
18+
print(u"successfully created {}".format(p.name))
19+
return p.id
20+
except Exception:
21+
print("unsuccessful", name)
22+
23+
24+
def fetch(url=None, all_projects=[]):
25+
url = url or base_url
26+
resp = requests.get(url)
27+
data = resp.json()
28+
results = data['results']
29+
30+
for project in results:
31+
canonical_url = project['canonical_url']
32+
try:
33+
p = Project.objects.all().filter(name=project['name'])
34+
if not p.exists():
35+
req = requests.get(canonical_url)
36+
if req.status_code == 200 and project['documentation_type'] == "sphinx":
37+
p = create_project(repo=project['repo'], name=project['name'],
38+
repo_type=project['repo_type'])
39+
if p:
40+
all_projects.append(p)
41+
42+
if len(all_projects) == 10000:
43+
print("Successufl")
44+
return None
45+
except ConnectionError:
46+
pass
47+
48+
next_url = data['next']
49+
fetch(url=next_url)
50+
51+
52+
fetch(url=base_url)

readthedocs/search/management/commands/reindex_elasticsearch.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,8 @@ def _run_reindex_tasks(self, models):
3939
model_name = qs.model.__name__
4040

4141
index_name = doc._doc_type.index
42-
timestamp_prefix = 'temp-{}-'.format(datetime.datetime.now().strftime('%Y%m%d%H%M%S'))
43-
new_index_name = timestamp_prefix + index_name
42+
timestamp = datetime.datetime.now().strftime('%Y%m%d%H%M%S')
43+
new_index_name = "{}_{}".format(index_name, timestamp)
4444

4545
pre_index_task = create_new_es_index_task.si(app_label=app_label,
4646
model_name=model_name,

0 commit comments

Comments
 (0)