forked from scrapinghub/shub
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
34 lines (30 loc) · 883 Bytes
/
Copy pathutils.py
File metadata and controls
34 lines (30 loc) · 883 Bytes
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
import sys, imp, os, netrc
SCRAPY_CFG_FILE = os.path.expanduser("~/.scrapy.cfg")
NETRC_FILE = os.path.expanduser('~/.netrc')
def missing_modules(*modules):
"""Receives a list of module names and returns those which are missing"""
missing = []
for module_name in modules:
try:
imp.find_module(module_name)
except ImportError:
missing.append(module_name)
return missing
def find_api_key():
"""Finds and returns the Scrapy Cloud APIKEY"""
key = os.getenv("SHUB_APIKEY")
if not key:
key = get_key_netrc()
return key
def get_key_netrc():
"""Gets the key from the netrc file"""
try:
info = netrc.netrc()
except IOError:
return
try:
key, account, password = info.authenticators("scrapinghub.com")
except TypeError:
return
if key:
return key