Skip to content

Commit

Permalink
Update tempdir, using tempfile
Browse files Browse the repository at this point in the history
  • Loading branch information
jimmysitu committed Aug 20, 2024
1 parent 439b943 commit 7a13227
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install -r requirements.txt
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand Down
2 changes: 1 addition & 1 deletion examples/get_xshg.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
proxy = 'socks5://127.0.0.1:1088'

stock = msf.Stock(
debug=True,
debug=True,
session='xshg.db3',
proxy=proxy,
)
Expand Down
9 changes: 7 additions & 2 deletions msfinance/stocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import json
import sqlite3
import requests
import tempfile

import pandas as pd

Expand Down Expand Up @@ -39,7 +40,7 @@
}

class StockBase:
def __init__(self, debug=False, browser='firefox', session='/tmp/msfinance/msfinance.db', proxy=None):
def __init__(self, debug=False, browser='firefox', session='msfinance.db3', proxy=None):
self.debug = debug
if('chrome' == browser):
# TODO: Add chrome support
Expand All @@ -49,7 +50,11 @@ def __init__(self, debug=False, browser='firefox', session='/tmp/msfinance/msfin
self.options = webdriver.FirefoxOptions()

# Settting download staff
self.download_dir = '/tmp/msfinance/' + str(os.getpid())
self.download_dir = os.path.join(tempfile.gettempdir(), 'msfinance', str(os.getpid()))

if not os.path.exists(self.download_dir):
os.makedirs(self.download_dir)

self.options.set_preference("browser.download.folderList", 2)
self.options.set_preference("browser.download.dir", self.download_dir)
self.options.set_preference("browser.download.useDownloadDir", True)
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ dependencies = [
"retrying",
"xlrd",
"lxml",
"tempfile",
"requests",
"pandas",
"selenium",
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
retrying
xlrd
lxml
tempfile
requests
pandas
selenium
Expand Down

0 comments on commit 7a13227

Please sign in to comment.