forked from saulpw/visidata
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- removePlugin to remove newline also
- Loading branch information
Showing
6 changed files
with
99 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
name plugin_ver release_date author visidata_ver description requirements | ||
name latest_ver latest_release author visidata_ver description requirements | ||
vfake 0.9 2019-02-08 Saul Pwanson <[email protected]> 1.6 replace column with fake values Faker |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.9 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,32 @@ | ||
# install the faker module: pip3 install Faker | ||
# copy this file into .visidata/fake.py | ||
# add "import fake" to .visidatarc | ||
|
||
# to anonymize a column in vd: do "setcol-fake" with e.g. 'name' 'isbn10' or any of the functions on Faker() | ||
|
||
from visidata import vd, Column, Sheet, option, options, asyncthread, Progress, undoEditCells | ||
|
||
Sheet.addCommand(None, 'setcol-fake', 'cursorCol.setValuesFromFaker(input("faketype: ", type="faketype"), selectedRows or rows)', undo=undoEditCells) | ||
__version__ = '0.9' | ||
|
||
option('locale', 'en_US', 'default locale to use for Faker', replay=True) | ||
|
||
vd.newvals = {None: None} | ||
vd.fakeMap = {} | ||
|
||
@Column.api | ||
@asyncthread | ||
def setValuesFromFaker(col, faketype, rows): | ||
import faker | ||
fake = faker.Faker(options.locale) | ||
fakefunc = getattr(fake, faketype) | ||
fakefunc = getattr(fake, faketype, None) or error('no such faker function') | ||
|
||
vd.fakeMap[None] = None | ||
vd.fakeMap[options.null_value] = options.null_value | ||
|
||
vd.newvals[options.null_value] = options.null_value | ||
for r in Progress(rows): | ||
v = col.getValue(r) | ||
if v in vd.newvals: | ||
newv = vd.newvals[v] | ||
if v in vd.fakeMap: | ||
newv = vd.fakeMap[v] | ||
else: | ||
newv = fakefunc() | ||
vd.newvals[v] = newv | ||
vd.fakeMap[v] = newv | ||
col.setValue(r, newv) | ||
|
||
|
||
Sheet.addCommand(None, 'setcol-fake', 'cursorCol.setValuesFromFaker(input("faketype: ", type="faketype"), selectedRows or rows)', undo=undoEditCells) | ||
Sheet.addCommand(None, 'reset-fake', 'vd.fakeMap.clear()') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters